Simply Convert Decimal To Hex

Hello,

I'm currently new at this and any form of coding language. I've been searching online about the answers and stuck.

Could someone teach me how to simply change a Dec Output number to Hex ?

Thank you.

Do you really want HEX as in a hexadecimal string?

Do you expect this to be encoded with 0x prefix?

did you look at the built examples in the FINS node...

... there are some good examples of data conversion in there.


Also, here is a demo you can import and play with...
chrome_9iOdly9Ie4

[
    {
        "id": "690a923280697d57",
        "type": "FINS Read",
        "z": "4cad319b1add5007",
        "name": "",
        "connection": "c61a613f.f2bde",
        "addressType": "str",
        "address": "D100",
        "countType": "num",
        "count": "1",
        "msgPropertyType": "msg",
        "msgProperty": "payload",
        "outputFormatType": "buffer",
        "outputFormat": "",
        "x": 938,
        "y": 304,
        "wires": [
            [
                "c169e3cdedda9122",
                "0a496520b5289d5e",
                "0e13de1b524bafc4"
            ]
        ]
    },
    {
        "id": "8a40ffeab5171b72",
        "type": "inject",
        "z": "4cad319b1add5007",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 767,
        "y": 304,
        "wires": [
            [
                "690a923280697d57"
            ]
        ],
        "l": false
    },
    {
        "id": "c169e3cdedda9122",
        "type": "buffer-parser",
        "z": "4cad319b1add5007",
        "name": "to hex",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "hex",
                "name": "item1",
                "offset": 0,
                "length": 2,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "value",
        "resultTypeType": "output",
        "multipleResult": true,
        "fanOutMultipleResult": false,
        "setTopic": false,
        "outputs": 1,
        "x": 1138,
        "y": 352,
        "wires": [
            [
                "3a714af1cd093f24"
            ]
        ]
    },
    {
        "id": "3a714af1cd093f24",
        "type": "debug",
        "z": "4cad319b1add5007",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1334,
        "y": 352,
        "wires": []
    },
    {
        "id": "0a496520b5289d5e",
        "type": "function",
        "z": "4cad319b1add5007",
        "name": "",
        "func": "msg.payload = msg.payload.toString(\"hex\")\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1148,
        "y": 400,
        "wires": [
            [
                "78e30adb89eb3755"
            ]
        ]
    },
    {
        "id": "78e30adb89eb3755",
        "type": "debug",
        "z": "4cad319b1add5007",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1334,
        "y": 400,
        "wires": []
    },
    {
        "id": "cf5c6c06454114da",
        "type": "inject",
        "z": "4cad319b1add5007",
        "name": "Random 10000~32000",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[(\t    $minimum := 10000;\t    $maximum := 32000;\t    $round(($random() * ($maximum-$minimum)) + $minimum, 0)\t)]",
        "payloadType": "jsonata",
        "x": 862,
        "y": 224,
        "wires": [
            [
                "0741d8c20b1e37ca",
                "c9745343f93e6d27"
            ]
        ]
    },
    {
        "id": "0741d8c20b1e37ca",
        "type": "FINS Write",
        "z": "4cad319b1add5007",
        "name": "",
        "connection": "c61a613f.f2bde",
        "addressType": "str",
        "address": "D100",
        "dataType": "msg",
        "data": "payload",
        "msgPropertyType": "msg",
        "msgProperty": "payload",
        "x": 1158,
        "y": 224,
        "wires": [
            []
        ]
    },
    {
        "id": "c9745343f93e6d27",
        "type": "debug",
        "z": "4cad319b1add5007",
        "name": "",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1158,
        "y": 160,
        "wires": []
    },
    {
        "id": "0e13de1b524bafc4",
        "type": "debug",
        "z": "4cad319b1add5007",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1334,
        "y": 304,
        "wires": []
    },
    {
        "id": "76f976fa02a171c1",
        "type": "comment",
        "z": "4cad319b1add5007",
        "name": "Using buffer parser",
        "info": "",
        "x": 1530,
        "y": 352,
        "wires": []
    },
    {
        "id": "7b80d84d0d4fe49f",
        "type": "comment",
        "z": "4cad319b1add5007",
        "name": "Using Function",
        "info": "",
        "x": 1520,
        "y": 400,
        "wires": []
    },
    {
        "id": "92fcafa404553cf8",
        "type": "comment",
        "z": "4cad319b1add5007",
        "name": "Buffer read from PLC",
        "info": "",
        "x": 1540,
        "y": 304,
        "wires": []
    },
    {
        "id": "c61a613f.f2bde",
        "type": "FINS Connection",
        "name": "",
        "host": "192.168.1.120",
        "port": "9600",
        "MODE": "",
        "MODEType": "CJ",
        "protocol": "",
        "protocolType": "udp",
        "ICF": "128",
        "DNA": "",
        "DA1": "120",
        "DA2": "",
        "SNA": "",
        "SA1": "50",
        "SA2": "",
        "autoConnect": true
    }
]
1 Like

It Works !!!
Thank you very much, and I'll make sure i would look at the example first in the future.
you are awesome!!! :+1::+1::+1:

1 Like

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