Guf*_*ffa 48
显而易见的方式; 使用带有字节数组的构造函数:
BitArray bits = new BitArray(arrayOfBytes);
Run Code Online (Sandbox Code Playgroud)
Tho*_*que 15
这取决于你对"位数组"的意思...如果你的意思是一个BitArray类的实例,Guffa的答案应该可以正常工作.
如果你真的想要一个比特数组,bool[]例如,你可以做类似的事情:
byte[] bytes = ...
bool[] bits = bytes.SelectMany(GetBits).ToArray();
...
IEnumerable<bool> GetBits(byte b)
{
for(int i = 0; i < 8; i++)
{
yield return (b & 0x80) != 0;
b *= 2;
}
}
Run Code Online (Sandbox Code Playgroud)