Reputation: 5804
I'm trying to understand what is going on with the following code.
console.log(buffer);
>>> <Buffer d6 16 06 37 f7 42 56 f6 45 56 37 47 27 e3 22 36 07 07 e0 c0 b9 85 d9 01 58 db 1b 59 19 db dc 0b 1c 5b 58 5e 99 dc cb 58 dd 1c dd 5b db 17 1c 5b 58 5e ... >
If i convert the some of the hex decimals to binary, i get the following bits.
1101 0110 0001
But i then convert it to a bitstream (https://github.com/inolen/bit-buffer), and read the bits.
const test = new bitBuffer.BitStream(buffer);
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
console.log(test.readBits(1, false));
0110 1011 0110
Why are these bits not exact? Was wondering if the hex of of the buffer, was simply the ram address? Hopefully someone can clear it up. :-)
Upvotes: 0
Views: 554
Reputation: 664246
First of all, buffers are not grouped into hex digits but into octets (bytes), so you should put the bits in groups of 8 not 4.
Each of those groups is simply reversed. That's because the human-readable representation is big-endian, and when you read the bit at index 0
that's the rightmost. So if you are reading them bit-by-bit from your stream, you read each byte from the right to the left.
Upvotes: 2