# MODBUS 16bit SIGNED INTEGER

**URL:** <https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362>\
**Category:** General\
**Created:** [23 April 2020 12:27 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362 "2020-04-23T12:27:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![farcry](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@farcry](https://discourse.nodered.org/u/farcry)\
**Post date:** [23 April 2020 12:27 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/1 "2020-04-23T12:27:44Z")

</div>

Hello.  
I'm reading MODBUS holding registers.  
On register 0 the value is -35 (signed).  
If I show this value in gage the value is 65501 (unsigned).  
How can I show SIGNED INTEGER?  
Thanks.  
BR.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 April 2020 12:41 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/3 "2020-04-23T12:41:31Z")

</div>

What do you get coming out of whatever node you are using for modbus? Feed it directly into a debug node and screenshot please.

---

<div class="post-metadata">

**Author:** ![farcry](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@farcry](https://discourse.nodered.org/u/farcry)\
**Post date:** [23 April 2020 13:10 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/4 "2020-04-23T13:10:34Z")

</div>

![Modbus](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0fbe293082c8c6cd9cc19fea5a15d7bf6ae68d20.png)

---

<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:** [23 April 2020 13:18 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/5 "2020-04-23T13:18:52Z")

</div>

is that directly from the MODBUS node?

Some of the modbus nodes output a buffer object.

And if it is a buffer then its pretty simple : in a function node (untested)...

```auto
let buf = msg.payload;
msg.converted = [];
msg.converted[0] = buf.readInt16BE();
msg.converted[1] = buf.readInt16BE();
msg.converted[2] = buf.readInt16BE();
//... etc ...
return msg;

```

see [buffer documentation](https://nodejs.org/api/buffer.html#buffer_buf_readint16be_offset) for a whole raft of `read` functions (for when you ask how to read floats next 😉 )

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 April 2020 14:38 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/6 "2020-04-23T14:38:05Z")

</div>

To use the data as in the debug then you can do, for each item in the array  
`msg.payload[i] = (msg.payload[i] << 16) >> 16`

---

<div class="post-metadata">

**Author:** ![farcry](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@farcry](https://discourse.nodered.org/u/farcry)\
**Post date:** [24 April 2020 07:23 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/7 "2020-04-24T07:23:34Z")

</div>

> [@Colin](#):
>
> msg.payload[i] = (msg.payload[i] \<\< 16) \>\> 16

Collin you are the best.  
Simple and effective sollution.  
BR.

---

<div class="post-metadata">

**Author:** ![farcry](https://avatars.discourse-cdn.com/v4/letter/f/9de053/32.png) [@farcry](https://discourse.nodered.org/u/farcry)\
**Post date:** [24 April 2020 07:33 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/8 "2020-04-24T07:33:58Z")

</div>

Collin.  
Off topic question.  
Do you have similar (simple) idea of how to show BCD formated numbers?  
I have posted: [OMRON BCD format](https://discourse.nodered.org/t/omron-bcd-format/24847)  
Thanks.  
BR.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 April 2020 08:10 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/9 "2020-04-24T08:10:46Z")

</div>

Ask for further help on that thread. One poster described how to do it, if that is not in sufficient detail then ask for further clarification.

---

<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 May 2020 08:10 UTC](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/10 "2020-05-08T08:10:54Z")

</div>

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