0

I want to ask, how to store a number (integer in JS) in buffer using buffer.writeInt16BE().

Assume I have a number such as

var a = 40000; 

40000(10) = 9C40 (16)

how can I store 40000 in buffer of size of 2, so it looks something like:

<9c, 40>

1 Answer 1

1

You can't use buf.writeInt16BE() because 40000 is larger than 32768. However if you use buf.writeUInt16BE() you can write 40000 to the buffer just fine.

Sign up to request clarification or add additional context in comments.

2 Comments

I am getting an error like: ReferenceError: writeUInt16BE is not defined
Those are methods available on the Buffer instance, not global functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.