从 bool[] 到 byte[]:将 bool[] 转换为 byte[]
但是我需要将 byte[] 转换为 List ,其中列表中的第一项是 LSB。
我尝试了下面的代码,但是当再次转换为字节并返回布尔值时,我得到了两个完全不同的结果......:
public List<bool> Bits = new List<bool>();
public ToBools(byte[] values)
{
foreach (byte aByte in values)
{
for (int i = 0; i < 7; i++)
{
Bits.Add(aByte.GetBit(i));
}
}
}
public static bool GetBit(this byte b, int index)
{
if (b == 0)
return false;
BitArray ba = b.Byte2BitArray();
return ba[index];
}