Reputation: 1
Bytes: 240 255 255 9 0 224 9 0
f0 ff ff 09 00 E0 09 00
Little endian unsigned int 64 translation:
00 09 E0 00 09 ff ff f0
int value1 = 0-19 bits
int value2 = 20-39 bits
int value3 = 40-59 bits
int value4 = 60-62 bits
bool value5 = 63 bit
value1 = (uint)(byteArray[0] | byteArray[1] << 8 | (byteArray[2] << 16)) & 0x14;
Am I doing this correctly? I keep getting value of 0 but should be 158.
Upvotes: 0
Views: 443
Reputation: 804
The last operation in your calculation is & 0x14
. This will do a bitwise and against the binary value of 0001 0100
. You're looking for the first 20 bits, so your mask should be 0xfffff
.
Upvotes: 1