Convert decimal to hex then store in binary buffer

Hello

I have a slider node that I slide from 0 to 40. The output is obviously a decimal number.

I need to convert this to hex, so I used var hexstring1 = "0x" + msg.payload.toString(16);

However, when I try to load this value into a binary buffer, say msg.payload = Buffer.from(0x00, [hexstring1], 0x00, 0x01);, I get an error.

How do I convert the decimal number so I can store it in the buffer?

I do have other values I am setting in the buffer, which are numbers.

Just put the number in there

Buffer.from([0x00, msg.payload, 0x00, 0x01]);

Shouldn't this be

Buffer.from([0x00, msg.payload, 0x00, 0x01]);

?

1 Like

Yes indeed. Written from phone/untested/pre-coffee) :wink:

Never do! High risc action! :wink:

2 Likes

Thank you!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.