Techiio-author
Started by Lidig TinilaloOct 1, 2021

Open
How does Node Buffer.getIntBE() calculate the negative numbers?

4 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 4 VIEWES SHARE

Node buffer reads signed values, but how does it know which algorithm to use? There are three ways, at least, to store a negative number in binary: 2s complement, 1s complement, and traditional.

For example, 1111 could be -7, -0, or -1.

How can Node know how to "unpack" the value and correctly convert it to a negative value? They all LOOK the same, and there's no way to configure when the buffer is initialized.

1 Replies

Techiio-commentatorNurjaman Shekh replied 19 days ago0 likes0 dislikes

It doesn't matter. Just read the documentation and the node explains all signed INTs as 2s complements.

Hope this helps someone in any situation.

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance