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

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....

[
    {
        "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"
            ]
        ]
    }
]

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

image

[{"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":[]}]
1 Like

Big thanks to you! This is what I need

All the best :slight_smile:

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