[C#][C++] BitArray class object

  • Context: C/C++ 
  • Thread starter Thread starter Silicon Waffle
  • Start date Start date
  • Tags Tags
    Class
Click For Summary
SUMMARY

The discussion focuses on converting a C# BitArray implementation to C++ using the Boost library's dynamic_bitset. The user initially employs the C# code `BitArray data=new BitArray(resource.ToArray());` and seeks an equivalent in C++. The suggested C++ implementation utilizes `boost::dynamic_bitset<> data(resource.begin(), resource.end());`. However, alternatives such as `std::vector` are also mentioned due to the compile-time limitations of C++'s standard bitset.

PREREQUISITES
  • Understanding of C# BitArray class and its functionality
  • Familiarity with C++ Boost library, specifically dynamic_bitset
  • Knowledge of C++ standard library containers, particularly std::vector
  • Basic concepts of bit manipulation in programming
NEXT STEPS
  • Research the differences between C# BitArray and C++ Boost dynamic_bitset
  • Explore the use of std::vector for dynamic bit storage in C++
  • Learn about memory management and performance implications of using Boost libraries
  • Investigate alternative libraries for bit manipulation in C++, such as `std::bitset` and `std::array`
USEFUL FOR

Developers transitioning from C# to C++, particularly those preparing for certification exams, as well as programmers interested in efficient bit manipulation techniques in both languages.

Silicon Waffle
Messages
160
Reaction score
202
I am learning both languages for coming certified exams :D
I have a code line in C# like this

Code:
byte[] resource=...;
BitArray data=new BitArray(resource.ToArray());
I would like to do this in C++ (I am using dynamic_bitset of boost - don't know if this a bad choice)

Code:
std::vector<unsigned char>resource=...
boost::dynamic_bitset<> data(resource.begin(),resource.end());
I am not a fan of boost, have you any other ways to covert the above C# code into C++. bitset of C++ only allows specification of template bitset size at compile time.
 
Last edited by a moderator:

Similar threads

  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
89
Views
7K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
6K
  • · Replies 10 ·
Replies
10
Views
4K