# Problem to convert signed hexadecimal to float

**URL:** <https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410>\
**Category:** General\
**Created:** [9 January 2023 13:30 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410 "2023-01-09T13:30:14Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [9 January 2023 13:30 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/1 "2023-01-09T13:30:14Z")

</div>

Hello,  
I am working on a node red project, and I want to read a voltage value.  
The problem is that the value I'm reading is a signed hexadecimal value, which doesn't give me the right voltage value.  
I would like to convert this signed hexadecimal value to a floating value.  
Can someone help me, please ?

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [9 January 2023 13:46 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/2 "2023-01-09T13:46:44Z")

</div>

Are you reading these values via Modbus?

Can you post an example of flow that you use?

---

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [9 January 2023 13:58 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/3 "2023-01-09T13:58:20Z")

</div>

I use parseInt function 🙂  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1853ef0a07f50d9739738b3544f0ee4fb571cc0.png)

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [9 January 2023 13:59 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/4 "2023-01-09T13:59:54Z")

</div>

Where do you get hex values from? Can you post full flow?

---

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [9 January 2023 14:07 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/5 "2023-01-09T14:07:10Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/576e49bfe0ea74bf58fa6be6b2b2e31c7585ee2d.png)

---

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [9 January 2023 14:10 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/6 "2023-01-09T14:10:35Z")

</div>

I use socketcan out to get the hex value and i converted it to decimal

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [9 January 2023 14:10 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/7 "2023-01-09T14:10:50Z")

</div>

Select the nodes which generate the issue and press export

[https://nodered.org/docs/user-guide/editor/workspace/import-export](https://nodered.org/docs/user-guide/editor/workspace/import-export)

It is hard to understand the issue because it is possible to translate from hex to float.

`[{"id":"1628789d76bcc9ed","type":"inject","z":"6ce20a4e7446e62d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"fefe","payloadType":"str","x":190,"y":860,"wires":[["77264eb7ae7f9bc0"]]},{"id":"77264eb7ae7f9bc0","type":"function","z":"6ce20a4e7446e62d","name":"hex to Float","func":"let decFromHex = parseInt(msg.payload, 16);\nmsg.payload = decFromHex /100\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":860,"wires":[["8ddee4ea1572836a"]]},{"id":"8ddee4ea1572836a","type":"debug","z":"6ce20a4e7446e62d","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":860,"wires":[]}]`

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [9 January 2023 14:14 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/8 "2023-01-09T14:14:10Z")

</div>

I haven't worked with socketcan but you are probably receiving a buffer of hex. In this case you should use a converter:

> **[node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser)**
>
> Node-red nodes to convert values to and from buffer/array. Supports Big/Little Endian, BCD, byte swapping and much more

This might help you:

> **[Understanding and Using Buffers In Node-Red](http://stevesnoderedguide.com/understanding-buffers-node-red)**
>
> How to use the buffers object in node-red. We look at working with strings, integers and floats with example flows and video.

there are plenty of examples in nodered forum also

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [9 January 2023 14:18 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/9 "2023-01-09T14:18:27Z")

</div>

I use `node-red-contrib-buffer-parser` for convert signed hexadecimal from PLC.

---

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [9 January 2023 14:23 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/10 "2023-01-09T14:23:58Z")

</div>

How do you use the parser buffer. I don't understand how it works ?

---

<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:** [9 January 2023 14:34 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/11 "2023-01-09T14:34:18Z")

</div>

There are built in examples (use `CTRL+I` in node-red to access examples)

There is also built in help (on the Node-red sidebar) and the readme is quite informative.

Lastly, there are tonnes of working examples around the forum where it has solved the same problem you have.

---

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [9 January 2023 14:46 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/12 "2023-01-09T14:46:52Z")

</div>

Can you gives the way on the forum to check the answers about my problem ?

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [9 January 2023 14:49 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/13 "2023-01-09T14:49:46Z")

</div>

Use the search facility (Magnifying Glass) Top Right Corner.

Please don't forget, we are all Volunteers here.

---

<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:** [9 January 2023 16:39 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/14 "2023-01-09T16:39:24Z")

</div>

Here is a post from your other thread: [Node Red socketcan output frame received problem - #5 by Steve-Mcl](https://discourse.nodered.org/t/node-red-socketcan-output-frame-received-problem/73297/5)

Here is a post where a buffer is converted to float: [Modbus TCP float to value - #35 by Steve-Mcl](https://discourse.nodered.org/t/modbus-tcp-float-to-value/58393/35)

---

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [16 January 2023 10:03 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/16 "2023-01-16T10:03:35Z")

</div>

Hello,  
I would like to retrieve a current value.  
When I debug, I get the hexadecimal signed value FC7C which corresponds in decimal to -900:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6a8d5049b07a9f22667a9aab50337a233ee2e6d0.png)

The problem is that when I want to convert this hex value to decimal using the function below, I get as decimal value 646,37 instead of -9 A.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/53635472de8ebce593b1072a2bad711adbcfa35a.png)

I don't understand how to do this, does anyone have a solution?  
Thanks

---

<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:** [16 January 2023 10:14 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/17 "2023-01-16T10:14:36Z")

</div>

> [@David321](#):
>
> When I debug, I get the hexadecimal signed value FC7C which corresponds in decimal to -900

If you use buffer parser to parse your values like I showed you in previous post, simply select the `int16` option and you will get the correct signed value

---

<div class="post-metadata">

**Author:** ![David321](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@David321](https://discourse.nodered.org/u/David321)\
**Post date:** [16 January 2023 10:56 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/19 "2023-01-16T10:56:02Z")

</div>

Thanks a lot, I managed to solve the problem :  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/118b4b4b28c6b983000ee1a63428fda313d0d8f3.png)

---

<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:** [17 March 2023 10:56 UTC](https://discourse.nodered.org/t/problem-to-convert-signed-hexadecimal-to-float/73410/20 "2023-03-17T10:56:53Z")

</div>

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