.NET Micro Framework 的 BitArray 替代方案
.NET Micro Framework 是否有 BitArray 替代方案? 我正在考虑简单地使用 bool[],但是如何将其转换回来 变成一个字节[]?
在完整的框架中,考虑到“bits”是一个 BitArray,以下工作:
byte[] data = new byte[dimensions / 8];
bits.CopyTo(data, 0);
但我似乎无法在微框架中找到 BitArray 类
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 802.15.4 堆栈中找到 BitArray 实现。只需在移植套件中搜索 BitArray.cs
You can find a BitArray Implementation in the 802.15.4 Stack. Just search the Porting Kit for BitArray.cs
我上传了 .net 微框架的数组:
http://code.tinyclr.com/project /310/bitarray-class/
希望这有帮助。
I uploaded an array for .net microframework:
http://code.tinyclr.com/project/310/bitarray-class/
Hope this helps.
复制 BitArray 的功能并不是非常困难。首先,如果您需要少于 65 位,那么您可以使用
long
或更小的值来实现。设置单个位:
清除位:
查看是否设置了位:
如果超过 64 位,则需要创建一个数组(可能是
byte[]
) ,然后进行除法以确定要修改的字节/位。只要将long
更改为byte
,上述方法就可以工作。例如,如果您有:
您有 1024 位。
设置位:
其他方法使用相同的数学来获取字节和位索引,并且设置、清除和测试位与上面的
long
示例相同。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.