# Format Buffer to HexString in function node

**URL:** <https://discourse.nodered.org/t/format-buffer-to-hexstring-in-function-node/72795>\
**Category:** General\
**Tags:** function-node\
**Created:** [27 December 2022 23:20 UTC](https://discourse.nodered.org/t/format-buffer-to-hexstring-in-function-node/72795 "2022-12-27T23:20:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lopikamper](https://avatars.discourse-cdn.com/v4/letter/l/c5a1d2/32.png) [@lopikamper](https://discourse.nodered.org/u/lopikamper)\
**Post date:** [27 December 2022 23:20 UTC](https://discourse.nodered.org/t/format-buffer-to-hexstring-in-function-node/72795/1 "2022-12-27T23:20:28Z")

</div>

Hi all,  
I need to do a rather simple task. I would like to format this Buffer:

```auto
var char = Buffer.from([0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xef])

```

in a function node (or any other way) as a HexString:

```auto
var str = "7e000000000000ffef"

```

To be able to send this hex stream via gatttool to bluetooth client.  
Unfortunately I got completely stuck. Could you please help me ?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [28 December 2022 01:28 UTC](https://discourse.nodered.org/t/format-buffer-to-hexstring-in-function-node/72795/2 "2022-12-28T01:28:40Z")

</div>

Hello .. you can try .. `.toString("hex")`

```auto
var char = Buffer.from([0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xef])

msg.payload = char.toString("hex")

return msg;

```

* * *

**Result:**

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a93ed0711ebe2bb25d6b9ffbbf46263a2ee74713.png)

.. alternatively you can use the [node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) node  
with these settings

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/139587b124ce56c93a204f7e40ffa750ad6f90f4.png)

that should give you the same result

---

<div class="post-metadata">

**Author:** ![lopikamper](https://avatars.discourse-cdn.com/v4/letter/l/c5a1d2/32.png) [@lopikamper](https://discourse.nodered.org/u/lopikamper)\
**Post date:** [28 December 2022 22:16 UTC](https://discourse.nodered.org/t/format-buffer-to-hexstring-in-function-node/72795/3 "2022-12-28T22:16:00Z")

</div>

> [@UnborN](#):
>
> `msg.payload = char.toString("hex")`

Hello !

It works. Nice and easy ! Thanks a lot.

---

<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:** [11 January 2023 22:16 UTC](https://discourse.nodered.org/t/format-buffer-to-hexstring-in-function-node/72795/4 "2023-01-11T22:16:37Z")

</div>

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