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

  • Thread starter Thread starter Silicon Waffle
  • Start date Start date
  • Tags Tags
    Class
Click For Summary
The discussion revolves around converting a C# code snippet that utilizes a BitArray into C++ using Boost's dynamic_bitset. The original C# code initializes a BitArray from a byte array, while the proposed C++ equivalent uses a vector of unsigned char to create a dynamic_bitset. However, there is a sentiment against using Boost, prompting the search for alternative methods. One suggestion is to consider using std::vector<bool>, which allows for a dynamic size but has its own limitations. The conversation highlights the challenges of handling bit manipulation in C++ compared to C#.
Silicon Waffle
Messages
160
Reaction score
203
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:
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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