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
I uploaded an array for .net microframework:
http://code.tinyclr.com/project/310/bitarray-class/
Hope this helps.
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 along
or 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 thelong
tobyte
.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
long
example above.You can find a BitArray Implementation in the 802.15.4 Stack. Just search the Porting Kit for BitArray.cs