# 6 hex numbers to 3 \* 2 hex split

**URL:** <https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861>\
**Category:** General\
**Tags:** split\
**Created:** [4 October 2021 22:21 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861 "2021-10-04T22:21:57Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon3021](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Simon3021](https://discourse.nodered.org/u/Simon3021)\
**Post date:** [4 October 2021 22:21 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/1 "2021-10-04T22:21:57Z")

</div>

I have ABCDEF - 6 hex numbers coming to node red however need them separate into 3 lots of 2 hex numbers left to right AB first CD second and etc. using function module in node red.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [4 October 2021 23:01 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/2 "2021-10-04T23:01:17Z")

</div>

Use the JavaScript slice() twice. Here is a link for you  
[https://www.w3schools.com/jsref/jsref\_slice\_string.asp](https://www.w3schools.com/jsref/jsref_slice_string.asp)

---

<div class="post-metadata">

**Author:** ![Simon3021](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Simon3021](https://discourse.nodered.org/u/Simon3021)\
**Post date:** [5 October 2021 02:53 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/3 "2021-10-05T02:53:18Z")

</div>

Thank you for reply, but that doesn't work for me.

I'm referring to HEX values in payload not strings.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 October 2021 06:30 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/4 "2021-10-05T06:30:20Z")

</div>

> [@Simon3021](#):
>
> I'm referring to HEX values in payload

JavaScript does not have a variable type HEX. What type is the data? Number, buffer, or what? Feed it into a debug node and see what it shows.

---

<div class="post-metadata">

**Author:** ![Simon3021](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Simon3021](https://discourse.nodered.org/u/Simon3021)\
**Post date:** [5 October 2021 08:21 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/5 "2021-10-05T08:21:55Z")

</div>

Hi, thanks for taking time to help me  
Debug message is:

I'm using "colour picker" in dashboard to generate color  
and message I get  
msg.payload : string[7]  
"#b3624c" which is HEX number

In this case  
b3 would be RED (179 DEC)  
62 would be GREEN (98 DEC)  
4c would be BLUE (76 DEC)  
or do I need to use different method to achieve that?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 October 2021 08:51 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/6 "2021-10-05T08:51:25Z")

</div>

> [@Simon3021](#):
>
> I get  
> msg.payload : string[7]  
> "#b3624c" which is HEX number

it's a string not a hex number (no such thing)

Use the slice function @zenofmud suggested to create 3 two character parts then you can use `parseInt` to convert the 3 hex strings to numbers.

---

<div class="post-metadata">

**Author:** ![Simon3021](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Simon3021](https://discourse.nodered.org/u/Simon3021)\
**Post date:** [5 October 2021 12:13 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/7 "2021-10-05T12:13:23Z")

</div>

```auto
[{"id":"a22d044f.37e61","type":"debug","z":"6cf58c60.5c2ec4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":2220,"wires":[]},{"id":"49cd18b5.1d00d8","type":"function","z":"6cf58c60.5c2ec4","name":"","func":"str == msg.payload;\nmsg == str.split(4,2);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":2220,"wires":[["a22d044f.37e61"]]},{"id":"45d91520.88ed9c","type":"inject","z":"6cf58c60.5c2ec4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123456","payloadType":"str","x":330,"y":2220,"wires":[["49cd18b5.1d00d8"]]}]

```

I'm stuck

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 October 2021 12:42 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/8 "2021-10-05T12:42:05Z")

</div>

You don't seem to using the slice function, as suggested.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 October 2021 12:44 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/9 "2021-10-05T12:44:01Z")

</div>

Also don't forget to include the `#` character in your test inject node.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 October 2021 12:52 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/10 "2021-10-05T12:52:20Z")

</div>

Msg must be an object so you need to set msg.payload to the result

---

<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:** [5 October 2021 18:41 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/11 "2021-10-05T18:41:27Z")

</div>

Of course you could set the ui Color picker to output a more suitable choice of objects

---

<div class="post-metadata">

**Author:** ![Simon3021](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Simon3021](https://discourse.nodered.org/u/Simon3021)\
**Post date:** [5 October 2021 23:55 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/12 "2021-10-05T23:55:07Z")

</div>

Hi , and thanks.

I'm new to this and getting nowhere with this.

can someone please write me exact solution that I place into Function node that will work,  
for what I need.

Thank you in advance

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 October 2021 06:31 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/13 "2021-10-06T06:31:34Z")

</div>

```auto
msg.payload = msg.payload.match(/[^#]{1,2}/g);
return msg;

```

that should return ["b3", "62", "4c"]. So payload[0] would be "b3" and payload[1] would be 62, etc.

---

<div class="post-metadata">

**Author:** ![Simon3021](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Simon3021](https://discourse.nodered.org/u/Simon3021)\
**Post date:** [6 October 2021 10:04 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/14 "2021-10-06T10:04:57Z")

</div>

Thank you for solution that works good,

sorry if there is bit off confusion,  
I was not aware that there is actual  
' split node ' as my was hidden.  
Thank you again

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 December 2021 10:05 UTC](https://discourse.nodered.org/t/6-hex-numbers-to-3-2-hex-split/51861/15 "2021-12-05T10:05:00Z")

</div>

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