# Reverse/split bytes

**URL:** <https://discourse.nodered.org/t/reverse-split-bytes/31885>\
**Category:** General\
**Created:** [22 August 2020 18:34 UTC](https://discourse.nodered.org/t/reverse-split-bytes/31885 "2020-08-22T18:34:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![New2Node](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@New2Node](https://discourse.nodered.org/u/New2Node)\
**Post date:** [22 August 2020 18:34 UTC](https://discourse.nodered.org/t/reverse-split-bytes/31885/1 "2020-08-22T18:34:18Z")

</div>

Hi, I’m loving Node red and learning how to manipulate messages! I have a question which I’m sure someone will find simple!

What’s the best way to reverse/spilt a string and return some data. For example, I have a meter which is sending power values (array buffer) which I’m converting to ASCII string, this is the output:

```auto

<STX(0000967038250000006025000000000000203954764800000040901300000000000000000000000000000000000000000040140464570000)<ETX><HT>

```

How to I split everything in the brackets into 16 byte chunks, then split into two byte words, take each byte and reverse the words.

So taking the first 16 byte chunk:

`0000967038250000`

`00 00 96 70 38 25 00 00`

`00 00 25 38 70 69 00 00`

= 253871

I want the message to print out like this:

kWh Import: 253,871 Kwh  
kWh Export: 0 Kwh  
kvarh Q1: 487,654 Kvarh  
kvarh Q2: 14 kvarh  
kvarh Q3: 0 kvarh  
kvarh Q4: 0 kvarh  
kVAh: 576,404 kVAh

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)\
**Post date:** [22 August 2020 19:22 UTC](https://discourse.nodered.org/t/reverse-split-bytes/31885/2 "2020-08-22T19:22:42Z")

</div>

Maybe following excellent node can do the job for you:

> **[node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser)**
>
> A dynamic node to convert values in a buffer or integer array into the many different data type(s). Supports Big/Little Endian, BCD, byte swapping and much more

---

<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:** [22 August 2020 19:42 UTC](https://discourse.nodered.org/t/reverse-split-bytes/31885/3 "2020-08-22T19:42:02Z")

</div>

The buffer parser that @janvda had suggested can seem a bit daunting with all the flexibility it provides but there are examples built in (node-red menu, import, examples, node-red-contrib-buffer-parser).

If you get stuck, give me a shout.

---

<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:** [21 October 2020 19:42 UTC](https://discourse.nodered.org/t/reverse-split-bytes/31885/4 "2020-10-21T19:42:03Z")

</div>

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