2's Complement to Signed Integer

elmatador

Member
Join Date
May 2008
Location
Canada
Posts
108
Hello All,

I will be communicating with some GE Multilin MPR over Modbus. I will be reading some RTD values from the multilin. The Multilin sends out this data in 2's complement,

Example:

A Value of -1234 will be sent out as 64302 over modbus.

When I receive this value of 64302, I want to convert it back to -1234. In RSLogix5000 is there a way to easily do this conversion. I am usling the Controllogix PLC.

Please let me know.

Thanks
 
You're making it sound like you need a conversion. You don't. Two's complement is the standard way of representing signed integers.

The bit pattern for 64302 and -1234 in a 16 bit word are exactly the same. It's all how you interpret the data, unsigned or signed. A-B by default treats a 16 bit integer as signed, so it will be -1234.
 
I have to read RTD values, which has a range of -40 to 200 degC.

So a -40 in the Multilin will be sent as 32728. When I have an INT data, it takes this value as 32728 rather than -40. So I will need to convert this data over.

The same goes for 200 degC, it will come in as -200 (which is 2's compl.) And then I need to convert to +200.

The 2's complement data coming in is not automatically being converted in the Controllogix.
 
Your last post doesn't represent a 2's compliment number. It sounds like a biased integer with the bias being 32768. The UINT equivalent to the 2's complement INT -40 is 65496.

Assuming this bias representation, with bit 15 set only, the value is 0. All bits set is +32767. No bits set is -32768. Sound right?

Keith
 
ok here is my understanding of how the data is coming from the Multilin.

-40:
Binary Form (16-bits)
1000000000101000

The 16th bit will be the sign bit, hence the 1 to represent -

Now converted to 2's complement:
0111111111011000
Which is equal to 32728

200:
Binary form (16-bits)
0000000011001000
Converted to 2's complement
1111111110011100

which is -200, which needs to be converted to 200
 
No, -40 is -40.
-40 interpreted as an unsigned integer would be 32728, or 0xFFD8.
You need to show some code, including exactly how you are receiving the number, and into what type.
If you are reading your value into a DINT say, well, you will see it as 32728. If on the other hand, you copy the bit pattern of the lower word of the DINT into an integer, you will see -40.
 
elmatador, you need to do some playing. The tag monitor window will allow you to display a set if bits in about any format you want. Create an INT data tag, enter -40 and display it as a binary value. you will see that -40 does NOT have the bit pattern you show in your post. It has the bit pattern of 1111 1111 1101 1000.

Just stick with this. If you put this bit patern in to a 16-bit signed integer tag it will display as -40.

The bit patern you show in your last post is NOT a 2's compliment representation. Given what you show it is a 15-bit absolute value with bit 16 being a sign bit. The easiest way I know to convert this is to do a bitwise AND of the value coming in with a mask of 16#7FFF and then do a negate conditional on bit 16.

Keith
 
I am not sure if I have read your post correctly but you could
try to subtract your value from zero and see if they come out as you want.

-200 minus 0 = +200

40 minus 0 = -40
 
Last edited:
Came back and read my post and was to late to edit it so have made a correction in this post

I am not sure if I have read your post correctly but you could
try to subtract your value from zero and see if they come out as you want.

0 minus -200 = +200

0 minus 40 = -40
 

Similar Topics

Hey Guys, I am doing some changes on an older omron CJ2M plc using CX programmer. I am adding an ethernet device that is actually using a Two's...
Replies
4
Views
1,089
So I'm using a P&F optical read head for positioning. The position data comes into the PLC as two SINT bytes. Monitoring those SINTs in my 1769...
Replies
2
Views
1,374
As you can see from the title, I have a number of questions/issues; Two different situations/issues: 1. Im reading Oil Pressure and Fuel Pressure...
Replies
17
Views
9,601
Hi guys, I have a problem with setting up the parameters for PowerFlex 525. So we have 4x motor connected in parallel to 1 PowerFlex, each motor...
Replies
8
Views
1,092
I set up a Mitisubishi test system on the bench. Q03UDSPU Q173DCPU MR-J3-40B HF-KP43 HMI is a LS XP50 TTA/KP43 I am trying to use a signed...
Replies
1
Views
398
Back
Top Bottom