Is it possible to declare a bit array in C++?

singh

Golden Member
Jul 5, 2001
1,449
0
0
Why do you want to use bit arrays? I would recommend that you use byte arrays and write your own manipulation functions for bits in those arrays.
 

manly

Lifer
Jan 25, 2000
13,059
3,817
136
Sure, there's a bitset type in the standard library. I'm not a C++ guru so look up the usage for yourself.

singh, why would you reinvent the wheel when the standard library already provides one?
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
I advise anyone against using C++ bit-fields because they can be very inefficient (depending on compiler's implementation). Unless the program saves a significant amount of memory by using bit-fields, I would recommend using bytes instead.

As for re-inventing the wheel, the poster does not seem to have a good grasp on bit-fields, so I think it would be better if he at least tried to do the operations himself before persuing the std library solutions.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
I have a nice binary vector class that I wrote. I could share it if you're interested.
What I use it for is a distributed satellite coverage program I'm working on. I have very large arrays of binary data (whether or not a point on the earth is visible to a particular satellite at a particular time) on different machines in a cluster.
Now, when I send them back over the network, I'm only sending about 1/8th as much data as if I had used a vector of bool or char type. Then I can consolidate the data 32 bits at a time with & and | operators.