'Converting BitArray to Byte
I have a code that converts BitArray values to byte[] values. I got the code also from stackoverflow.
The code is working great, I just don't understand one part.
When the codes copies the BitArray to Byte using BitArray.CopyTo() the byte reading is in LSB order.
Can someone help me understand why the converted byte is in LSB order?
strBit (is a string value that consists of 1/0)
byte[] myByte = new byte[50];
List<string> list = Enumerable.Range(0, strBit.Length / 8)
.Select(i => strBit.Substring(i * 8, 8))
.ToList();
for (int x = 0; x < list.Count; x++)
{
BitArray myBitArray = new BitArray(list[x].ToString().Select(c => c == '1').ToArray());
myBitArray.CopyTo(myByte, x);
}
Example Output:
strBit[0] = 10001111 (BitArray)
when converted to Byte:
myByte[0] = 11110001 (Byte) (241/F1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
