Splitting hex value

Building an interface with a touchscreen from 4D Systems - in the documentation it states to write to a number on the screen, the value needs to be:

This is the 2 byte value, Value(msb):Value(lsb), that is used in the
message transmissions to and from the host. For example, if the LED
Digits value is 5645 (0x160D) the 2 byte value will be:
Value(msb) = 0x16
Value(lsb) = 0x0D

I am receiving a value from Modbus that I want to pass onto the screen,
ie. 1350 rpm or 0x546 but cannot get my head around how to split the value into two bytes.

Appreciate any advice.

Apologies for answering my own question, but after some tinkering I come up with this -

var b1 = 0;
var b2 = 0;
var num = msg.payload;

b1 = (num >> 8);
b2 =  (num & 0xFF);
msg = {payload: ([b1,b2,num])};
return msg;

and it works fine. Feel free to critique or add further advice.

1 Like

Perfectly fine and readable.

Much appreciated dceejay.
Got stuck in my head with trying to spit a hex value rather than the actual value.
Hex, Dec, Bin - it doesn't care just use the tools you have :smiley:

That's not something to apologize for. To the contrary, now someone else might stumble across this in a google search and benefit from it.


  1. sorry for my bad english :slight_smile:

I´m a node red noob.
I have a sensor it brings me by i2c - 8 bytes reotur.
So thats my problem, how i can get only 2 bytes in decimal?
I need byte:0 and byte:4

Pleas can someone help me, pleas.

nobody has an idea :frowning:

We were all asleep in my country :slight_smile:
This change node will get you the 4th item - 0 would get you the 1st