# Modbus: How to read 32 bit signed numbers

**URL:** <https://discourse.nodered.org/t/modbus-how-to-read-32-bit-signed-numbers/52021>\
**Category:** General\
**Created:** [8 October 2021 15:45 UTC](https://discourse.nodered.org/t/modbus-how-to-read-32-bit-signed-numbers/52021 "2021-10-08T15:45:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krish7](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krish7/32/47045_2.png) [@krish7](https://discourse.nodered.org/u/krish7)\
**Post date:** [8 October 2021 15:45 UTC](https://discourse.nodered.org/t/modbus-how-to-read-32-bit-signed-numbers/52021/1 "2021-10-08T15:45:28Z")

</div>

How to read 32 signed numbers over modbus ?  
I was using  
`var msg1 = {payload:(msg.payload[1]<<16)+msg.payload[0]};`  
code to create 32 bit numbers and toFloat function to convert it to float. However it's not showing the correct value (the output of msg1).  
I tried `msg.payload=(msg.payload[0])+(-msg.payload[1] << 32)` as well with no luck.  
Any suggestions

---

<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:** [8 October 2021 15:52 UTC](https://discourse.nodered.org/t/modbus-how-to-read-32-bit-signed-numbers/52021/2 "2021-10-08T15:52:25Z")

</div>

The simplest way is with [node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser)

Search this forum for `node-red-contrib-buffer-parser modbus` there are quite a few examples.

If you don't want to or can't then look at the nodejs Buffer functions.

---

<div class="post-metadata">

**Author:** ![krish7](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krish7/32/47045_2.png) [@krish7](https://discourse.nodered.org/u/krish7)\
**Post date:** [9 October 2021 16:03 UTC](https://discourse.nodered.org/t/modbus-how-to-read-32-bit-signed-numbers/52021/3 "2021-10-09T16:03:53Z")

</div>

I tried that, but not getting the negative numbers. Any scripts available to convert two registers to float( including negative) numbers ?

---

<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 October 2021 17:13 UTC](https://discourse.nodered.org/t/modbus-how-to-read-32-bit-signed-numbers/52021/4 "2021-10-09T17:13:50Z")

</div>

> [@krish7](#):
>
> I tried that, but not getting the negative numbers

Did you chose int32xx ?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0fa214cd76500d057ab9f419e53f3c2f3bcfbe6e.png)

uint32 == unsigned int (0 ~ 4bn)  
int == signed int (-2bn ~ 2bn)

Show me the output of the modbus node (use debug node)

---

<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:** [8 December 2021 17:14 UTC](https://discourse.nodered.org/t/modbus-how-to-read-32-bit-signed-numbers/52021/5 "2021-12-08T17:14:11Z")

</div>

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