# Convert number into binary, then split in half and convert again

**URL:** <https://discourse.nodered.org/t/convert-number-into-binary-then-split-in-half-and-convert-again/57279>\
**Category:** General\
**Created:** [26 January 2022 17:45 UTC](https://discourse.nodered.org/t/convert-number-into-binary-then-split-in-half-and-convert-again/57279 "2022-01-26T17:45:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![json\_lame](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@json\_lame](https://discourse.nodered.org/u/json_lame)\
**Post date:** [26 January 2022 17:45 UTC](https://discourse.nodered.org/t/convert-number-into-binary-then-split-in-half-and-convert-again/57279/1 "2022-01-26T17:45:08Z")

</div>

Hi there

I've got that number: 11580  
In binary this is: 0010 1101 0011 1100

Now I need to split this in half, like this: 0010 1101 and 0011 1100, then decode this into decimal and it should be 45 and 60. Could someone help with this?

This is my flow and it isn't work well, because it puts both numbers to the same payload....

```auto
[
    {
        "id": "74fa0afad927fa8f",
        "type": "tab",
        "label": "Flow 5",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "6ac46561bcd8b987",
        "type": "inject",
        "z": "74fa0afad927fa8f",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "11580",
        "payloadType": "num",
        "x": 90,
        "y": 100,
        "wires": [
            [
                "4be09b3653750579"
            ]
        ]
    },
    {
        "id": "1a38bb5e46de5832",
        "type": "debug",
        "z": "74fa0afad927fa8f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 890,
        "y": 100,
        "wires": []
    },
    {
        "id": "4be09b3653750579",
        "type": "bitunloader",
        "z": "74fa0afad927fa8f",
        "name": "",
        "mode": "string",
        "prop": "payload",
        "padding": "16",
        "x": 290,
        "y": 100,
        "wires": [
            [
                "d39601b217f559fe"
            ]
        ]
    },
    {
        "id": "e94c0218485b7eae",
        "type": "bitreloader",
        "z": "74fa0afad927fa8f",
        "name": "",
        "autoMode": "auto",
        "prop": "_prop",
        "mode": "_mode",
        "x": 680,
        "y": 100,
        "wires": [
            [
                "1a38bb5e46de5832"
            ]
        ]
    },
    {
        "id": "d39601b217f559fe",
        "type": "split",
        "z": "74fa0afad927fa8f",
        "name": "",
        "splt": "8",
        "spltType": "len",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 490,
        "y": 100,
        "wires": [
            [
                "e94c0218485b7eae"
            ]
        ]
    }
]

```

---

<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:** [26 January 2022 17:53 UTC](https://discourse.nodered.org/t/convert-number-into-binary-then-split-in-half-and-convert-again/57279/2 "2022-01-26T17:53:54Z")

</div>

There is no need to convert to binary. Simply AND the value and shift it.

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

```auto
[{"id":"024644f8c56bbc11","type":"inject","z":"950e6f56f9415563","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"11580","payloadType":"num","x":1040,"y":700,"wires":[["43354a26f97fc022"]]},{"id":"43354a26f97fc022","type":"function","z":"950e6f56f9415563","name":"","func":"msg.payload = {\n lo: (msg.payload & 0xff),\n hi: ((msg.payload & 0xff00) >> 8)\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":700,"wires":[["9f61dbfba0bde711"]]},{"id":"9f61dbfba0bde711","type":"debug","z":"950e6f56f9415563","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1350,"y":700,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![json\_lame](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@json\_lame](https://discourse.nodered.org/u/json_lame)\
**Post date:** [26 January 2022 18:03 UTC](https://discourse.nodered.org/t/convert-number-into-binary-then-split-in-half-and-convert-again/57279/3 "2022-01-26T18:03:10Z")

</div>

Big thanks to you! This is what I need

All the best 🙂

---

<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:** [9 February 2022 18:04 UTC](https://discourse.nodered.org/t/convert-number-into-binary-then-split-in-half-and-convert-again/57279/4 "2022-02-09T18:04:05Z")

</div>

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