【发布时间】:2023-03-21 18:42:02
【问题描述】:
从 bool[] 到 byte[]:Convert bool[] to 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];
}
【问题讨论】:
-
有什么理由不使用BitArray Class 来表示整个字节数组而不是每个单字节?
标签: c# byte boolean steganography