Friday, 2 July 2021

Sum hex from Node Buffer for 2's complement

I have a node buffer.

<Buffer 0a 80 04 06 20 ff ff ...

let buffTotal = 0;

for (const item of fileBuff) {
  console.log(item) 
  buffTotal = buffTotal + item;
}

console.log((~buffTotal + 1 >>> 0).toString(16))

I'm attempting to loop through the Buffer and add up all the hex values to calculate the single byte 2's complement, however I just get a very long hex string instead of a single byte representing the 2's complement sum of characters.



from Sum hex from Node Buffer for 2's complement

No comments:

Post a Comment