# Ascii string to hex

**URL:** <https://discourse.nodered.org/t/ascii-string-to-hex/33138>\
**Category:** General\
**Created:** [21 September 2020 08:39 UTC](https://discourse.nodered.org/t/ascii-string-to-hex/33138 "2020-09-21T08:39:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![goc333](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@goc333](https://discourse.nodered.org/u/goc333)\
**Post date:** [21 September 2020 08:39 UTC](https://discourse.nodered.org/t/ascii-string-to-hex/33138/1 "2020-09-21T08:39:15Z")

</div>

Hello everyone,

I have some data in database that I need to sand on mqtt.  
My data looks like this : 50C0E54373C3B68  
First thing I need to do is converting this string to hex to look like this:  
0x50 0xC0 0xE0...  
I tried to read every byte and save it to array with this code:

```auto
var desKey = msg.payload[0].desKey;;
var raw = new Buffer(26);

raw [0] = desKey[0];
raw [1] = desKey[1];
raw [2] = desKey[2];
raw [3] = desKey[3];
raw [4] = desKey[4];
raw [5] = desKey[5];

msg.payload = raw;
retrun msg;

```

but if character is not number array is empty.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/1405dd305f91c653e88baddd2097bb7bee4f5c89.png)

how can I get 0xA 0xB 0xC... values to my array?

---

<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:** [21 September 2020 08:44 UTC](https://discourse.nodered.org/t/ascii-string-to-hex/33138/2 "2020-09-21T08:44:19Z")

</div>

use a function node...

```auto
var buf = Buffer.from("50C0E54373C3B68","hex"); //change the fixed string to msg.payload or whatever
msg.payload = buf;
return msg;

```

Proof...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/c/cc01f0aced781ea3a202fa9e84de369dd31a0249.png)

---

<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 October 2020 08:44 UTC](https://discourse.nodered.org/t/ascii-string-to-hex/33138/3 "2020-10-05T08:44:24Z")

</div>

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