Let's say I have a hexadecimal data stream that I want to split into 3-byte blocks, which I need to read as a whole.
For example: with the given hexadecimal string 01be638119704d4b9a I need to read the first three bytes of 01be63 and consider it an integer 114275 . This is what I got:
var sample = '01be638119704d4b9a'; var buffer = new Buffer(sample, 'hex'); var bufferChunk = buffer.slice(0, 3); var decimal = bufferChunk.readUInt32BE(0);
readUInt32BE works fine for 4-byte data, but here I obviously get:
RangeError: index out of range at checkOffset (buffer.js:494:11) at Buffer.readUInt32BE (buffer.js:568:5)
How did I read 3 bytes correctly as a whole?
kmachnicki
source share