# Simply Convert Decimal To Hex

**URL:** https://discourse.nodered.org/t/simply-convert-decimal-to-hex/57264
**Category:** General
**Created:** [26 January 2022 14:04 UTC](https://discourse.nodered.org/t/simply-convert-decimal-to-hex/57264 "2022-01-26T14:04:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Limninzz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/limninzz/32/78007_2.png) [@Limninzz](https://discourse.nodered.org/u/Limninzz)
#### Post date: [26 January 2022 14:04 UTC](https://discourse.nodered.org/t/simply-convert-decimal-to-hex/57264/1 "2022-01-26T14:04:21Z")

</div>

Hello,

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

 ![nodered](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce62a463b68ddc3180667292336199ce4601c919.png)

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

Thank you.

---

<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 14:17 UTC](https://discourse.nodered.org/t/simply-convert-decimal-to-hex/57264/2 "2022-01-26T14:17:16Z")

</div>

> [@Limninzz](#):
>
> Could someone teach me how to simply change a Dec Output number to Hex

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/085f46f52cecddfca57de6492d9e618a38395923.png)

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

* * *

Also, here is a demo you can import and play with...  
 ![chrome_9iOdly9Ie4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/16d4dec8eeeeb526302899a7138055b0dc1c39d9.gif)

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

```

---

<div class="post-metadata">

### Author: ![Limninzz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/limninzz/32/78007_2.png) [@Limninzz](https://discourse.nodered.org/u/Limninzz)
#### Post date: [26 January 2022 14:32 UTC](https://discourse.nodered.org/t/simply-convert-decimal-to-hex/57264/3 "2022-01-26T14:32:07Z")

</div>

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

---

<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 14:33 UTC](https://discourse.nodered.org/t/simply-convert-decimal-to-hex/57264/4 "2022-02-09T14:33:00Z")

</div>

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