Is there a BitArray alternative for the .NET Micro Framework?
I was thinking about simply using a bool[], but how can you convert it back
into a byte[] ?
In the full framework, considering “bits” is a BitArray, the following works:
byte[] data = new byte[dimensions / 8];
bits.CopyTo(data, 0);
But I cannot seem to find the BitArray class in the micro framework
It’s not terribly difficult to duplicate the functionality of
BitArray. First, if you need fewer than 65 bits, then you can do it with alongor smaller.To set an individual bit:
To clear a bit:
To see if a bit is set:
If you have more than 64 bits, then you’ll need to create an array (
byte[], probably), and do the division to determine which byte/bit you want to modify. The methods above will work, provided you change thelongtobyte.For example, if you have:
You have 1024 bits.
To set a bit:
The other methods use the same math to get the byte and bit index, and setting, clearing, and testing a bit is the same as with the
longexample above.