您可以像这样获取这些位并将它们反转:
byte[] data = { 0x0E, 0xDC, 0x00, 0x1B, 0x80 };
// get only first four bytes
byte[] bits = new byte[4];
Array.Copy(data, 0, bits, 0, 4);
// reverse array if system uses little endian
if (BitConverter.IsLittleEndian) {
Array.Reverse(bits);
}
// get a 32 bit integer from the four bytes
int n = BitConverter.ToInt32(bits, 0); // 0x0EDC001B
// isolate the 18 bits by shifting and anding
n >>= 8; // 0x000EDC00
n &= 0x0003FFFF; // 0x0002DC00
// reverse by shifting bits out to the right and in from the left
int result = 0;
for (int i = 0; i < 18; i++) {
result = (result << 1) + (n & 1);
n >>= 1;
}
Console.WriteLine(result);
输出:
237