# Splitting hex value

**URL:** <https://discourse.nodered.org/t/splitting-hex-value/14757>\
**Category:** General\
**Created:** [25 August 2019 02:44 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757 "2019-08-25T02:44:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![atomic10](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/atomic10/32/11329_2.png) [@atomic10](https://discourse.nodered.org/u/atomic10)\
**Post date:** [25 August 2019 02:44 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/1 "2019-08-25T02:44:17Z")

</div>

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:  
_Value(msb:lsb)_

_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.

---

<div class="post-metadata">

**Author:** ![atomic10](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/atomic10/32/11329_2.png) [@atomic10](https://discourse.nodered.org/u/atomic10)\
**Post date:** [25 August 2019 03:20 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/2 "2019-08-25T03:20:30Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 August 2019 07:06 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/3 "2019-08-25T07:06:07Z")

</div>

Perfectly fine and readable.

---

<div class="post-metadata">

**Author:** ![atomic10](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/atomic10/32/11329_2.png) [@atomic10](https://discourse.nodered.org/u/atomic10)\
**Post date:** [25 August 2019 08:12 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/4 "2019-08-25T08:12:59Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [25 August 2019 16:16 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/5 "2019-08-25T16:16:59Z")

</div>

> [@atomic10](#):
>
> Apologies for answering my own question

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.

---

<div class="post-metadata">

**Author:** ![mike1976](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mike1976](https://discourse.nodered.org/u/mike1976)\
**Post date:** [23 November 2019 22:06 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/6 "2019-11-23T22:06:38Z")

</div>

Hello,

1. sorry for my bad english 🙂

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.

 ![i2c%202](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7b1aa962a202c18b1dd4975e39a1a0edd392d9e5.png) ![i2c%203](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/762ace70db6d8df6a2d2e8e0379ff2b4895b6d13.jpeg)

---

<div class="post-metadata">

**Author:** ![mike1976](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mike1976](https://discourse.nodered.org/u/mike1976)\
**Post date:** [24 November 2019 09:16 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/7 "2019-11-24T09:16:45Z")

</div>

nobody has an idea ☹

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [24 November 2019 09:26 UTC](https://discourse.nodered.org/t/splitting-hex-value/14757/8 "2019-11-24T09:26:59Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/47218f46c9569adceb7f0e3f631e032d59aa38c6.png)
