可能重复:
How i can convert BitArray to single int?
如何将整数读取到BitArray(6) (假设它可以包含),以及如何将BitArray(6)转换为无符号/有符号整数。
发布于 2011-11-15 23:43:16
byte[] bytes = { 0, 0, 0, 25 };
// If the system architecture is little-endian (that is, little end first),
// reverse the byte array.
if (BitConverter.IsLittleEndian)
Array.Reverse(bytes);
int i = BitConverter.ToInt32(bytes, 0);
Console.WriteLine("int: {0}", i);
// Output: int: 25发布于 2011-11-15 23:44:58
BitArray FromInt32(Int32 a)
{
byte[] bytes = BitConverter.GetBytes(a);
return new BitArray(bytes);
}如前面所述,对于反向操作,see this question。
https://stackoverflow.com/questions/8144709
复制相似问题