# Parsing binary encoded data from decimal array

**URL:** <https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205>\
**Category:** General\
**Created:** [29 September 2025 01:31 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205 "2025-09-29T01:31:18Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [3 October 2025 20:39 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205/21 "2025-10-03T20:39:13Z")

</div>

might also look at node-red-contrib-bitunloader, which parses integers such as your `383` into a few different forms of binary output, depending on how you want to process it. But under the hood it just converts numbers into a binary string `(383).toString(2).padStart(16,'0') //for a 16 bit number`

Personally I'd map each array index to an object property with a meaningful name, then process each of these individually in series until you get a well formed object with all needed information.

---

<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:** [3 October 2025 22:42 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205/22 "2025-10-03T22:42:04Z")

</div>

> [@gemini86](#):
>
> Personally I'd map each array index to an object property with a meaningful name, then process each of these individually in series until you get a well formed object with all needed information

Exactly what buffer parser does

> [@gemini86](#):
>
> which parses integers such as your `383` into a few different forms of binary output, depending on how you want to process it

Exactly what buffer parser does.

---

<div class="post-metadata">

**Author:** ![gemini86](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gemini86/32/70967_2.png) [@gemini86](https://discourse.nodered.org/u/gemini86)\
**Post date:** [3 October 2025 22:49 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205/23 "2025-10-03T22:49:38Z")

</div>

Perfect then.

---

<div class="post-metadata">

**Author:** ![trialnerror](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@trialnerror](https://discourse.nodered.org/u/trialnerror)\
**Post date:** [4 October 2025 12:37 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205/24 "2025-10-04T12:37:38Z")

</div>

With Claude.ai's help I've ended up with this function

```auto
[
    {
        "id": "393939344a9cb6e3",
        "type": "inject",
        "z": "b3efb06892b4f0b6",
        "name": "Create Buffer",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[5,901,1260,383,720,840,65,720,900,62,1260,1439,383,0,480,383,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
        "payloadType": "json",
        "x": 450,
        "y": 3060,
        "wires": [
            [
                "dddbc461ef50e71a",
                "d35da5f211a44433"
            ]
        ]
    },
    {
        "id": "dddbc461ef50e71a",
        "type": "function",
        "z": "b3efb06892b4f0b6",
        "name": "Claude",
        "func": "// Input array from msg.payload\nconst data = msg.payload;\n\n// Extract number of periods\nconst numPeriods = data[0];\n\n// Function to decode mode and days\nfunction decodeModeAndDays(value) {\n // Extract lower 8 bits (days of week)\n const daysValue = value & 0xFF;\n \n // Extract upper 8 bits (mode flag)\n const mode = (value >> 8) & 0xFF;\n \n // Decode individual days (bits 0-6 represent days)\n const days = {\n Sunday: (daysValue & 0x01) !== 0,\n Monday: (daysValue & 0x02) !== 0,\n Tuesday: (daysValue & 0x04) !== 0,\n Wednesday: (daysValue & 0x08) !== 0,\n Thursday: (daysValue & 0x10) !== 0,\n Friday: (daysValue & 0x20) !== 0,\n Saturday: (daysValue & 0x40) !== 0\n };\n \n // Get active days as array\n const activeDays = Object.keys(days).filter(day => days[day]);\n \n return {\n mode: mode === 1 ? \"Discharge\" : \"Charge\",\n modeValue: mode,\n daysValue: daysValue,\n days: days,\n activeDays: activeDays,\n binary: value.toString(2).padStart(16, '0')\n };\n}\n\n// Function to convert minutes to time string\nfunction minutesToTime(minutes) {\n const hours = Math.floor(minutes / 60);\n const mins = minutes % 60;\n return `${hours.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}`;\n}\n\n// Parse all periods\nconst periods = [];\nfor (let i = 0; i < numPeriods; i++) {\n const baseIndex = 1 + (i * 3); // Each period uses 3 values\n \n const startTime = data[baseIndex];\n const endTime = data[baseIndex + 1];\n const flagDays = data[baseIndex + 2];\n \n const decoded = decodeModeAndDays(flagDays);\n \n periods.push({\n period: i + 1,\n startTimeFormatted: minutesToTime(startTime),\n endTimeFormatted: minutesToTime(endTime),\n mode: decoded.mode,\n activeDays: decoded.activeDays,\n daysDetail: decoded.days,\n binary: decoded.binary\n });\n}\n\n// Output the decoded data\nmsg.payload = {\n numberOfPeriods: numPeriods,\n periods: periods\n};\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 720,
        "y": 3200,
        "wires": [
            [
                "81a16b5f21889ecf"
            ]
        ]
    },
    {
        "id": "81a16b5f21889ecf",
        "type": "debug",
        "z": "b3efb06892b4f0b6",
        "name": "debug 8",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 920,
        "y": 3200,
        "wires": []
    }
]

```

It's a little bit overkill really, but very easy to see what's coming out. Once I've worked out exactly how I want to use the output I'll probably remove anything that's surplus.

I tried @berijan 's buffer-parser flow - good to understand how that would work, I had tried but failed.

These AI tools open up a whole new world to we bumbling programmers. No way I could have produced something like that in less than a week, if ever!  
It must be turning the industry on it's head.

---

<div class="post-metadata">

**Author:** ![berijan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/berijan/32/35313_2.png) [@berijan](https://discourse.nodered.org/u/berijan)\
**Post date:** [6 October 2025 06:15 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205/25 "2025-10-06T06:15:19Z")

</div>

> [@trialnerror](#):
>
> I tried @berijan 's buffer-parser flow - good to understand how that would work, I had tried but failed.

What was it that failed?

I used Your array as input for my test and got out the data You wanted.  
Can I be that I used uint16be (Big Endian) but Your actual data is uint16le (Little Endian).

---

<div class="post-metadata">

**Author:** ![trialnerror](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@trialnerror](https://discourse.nodered.org/u/trialnerror)\
**Post date:** [6 October 2025 07:51 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205/26 "2025-10-06T07:51:40Z")

</div>

I wasn't clear sorry.

I failed to figure how to make buffer-parser work when I first tried.

Your node worked fine, & now I have a better understanding of how to parse the individual bits, thanks.

---

<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:** [4 January 2026 07:52 UTC](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205/27 "2026-01-04T07:52:18Z")

</div>

Closed on 4 January 2026 07:52 UTC

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

[Previous page](https://discourse.nodered.org/t/parsing-binary-encoded-data-from-decimal-array/99205.md?page=1)
