# Set Hex Value in a Change Node

**URL:** https://discourse.nodered.org/t/set-hex-value-in-a-change-node/15917
**Category:** General
**Created:** [25 September 2019 22:00 UTC](https://discourse.nodered.org/t/set-hex-value-in-a-change-node/15917 "2019-09-25T22:00:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dudleyjosh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudleyjosh/32/105799_2.png) [@dudleyjosh](https://discourse.nodered.org/u/dudleyjosh)
#### Post date: [25 September 2019 22:00 UTC](https://discourse.nodered.org/t/set-hex-value-in-a-change-node/15917/1 "2019-09-25T22:00:02Z")

</div>

If need to send the hex value of 0x18 to a serial port node, what is the proper way to do it using a Change node? I've found that is can be done using the following string "\u0018" within a JSONata expression field (I don't exactly understand why) but I am wondering if I am missing something simple and if there is a better way?

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [26 September 2019 02:00 UTC](https://discourse.nodered.org/t/set-hex-value-in-a-change-node/15917/2 "2019-09-26T02:00:29Z")

</div>

There are several places where you can enter data as a byte array, e.g. `inject` and `change` nodes. However, the implementation of the input editor is a bit... obscure:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/363f8e24a20167a92d57570528529e85bc6771c9.png)

If you read the Info panel closely, you _may_ discover that you can enter an array of "character codes", which will be stored as their byte equivalents -- but I doubt it. I had to be shown this by Dave himself...

In JSON syntax, `["0x18"]` represents an array of 1 byte, with hex value `18` -- where as if that character is entered as `["18"]`, it's interpretted as 1 char of **decimal** value 18 and stored as the hex byte `12`

---

<div class="post-metadata">

### Author: ![dudleyjosh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudleyjosh/32/105799_2.png) [@dudleyjosh](https://discourse.nodered.org/u/dudleyjosh)
#### Post date: [26 September 2019 02:39 UTC](https://discourse.nodered.org/t/set-hex-value-in-a-change-node/15917/3 "2019-09-26T02:39:50Z")

</div>

Thanks @shrickus, I'll give it a try tomorrow.

---

<div class="post-metadata">

### Author: ![dudleyjosh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dudleyjosh/32/105799_2.png) [@dudleyjosh](https://discourse.nodered.org/u/dudleyjosh)
#### Post date: [26 September 2019 20:47 UTC](https://discourse.nodered.org/t/set-hex-value-in-a-change-node/15917/4 "2019-09-26T20:47:18Z")

</div>

@shrickus I had a chance to mess with that today and this is what I found...

If I send the buffer value ["0x18"] directly to the serialport it does not work the same as if I send it the JSONata string value of "\u0018". However, if I perform a toString() operation on the buffer value, then send it to the serialport, it works as expected/needed?

I wish I understood why?

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [27 September 2019 01:08 UTC](https://discourse.nodered.org/t/set-hex-value-in-a-change-node/15917/5 "2019-09-27T01:08:03Z")

</div>

Ah, me too -- only thing I can think of is that the buffer is only 1 byte long, where the character string (of 1 char) is actually 2 bytes?

If the protocol expects 2 bytes, you _might_ want to try left padding with 0, so `["0x00", "0x18"]`?
