2's Complement to Signed Integer

Mountain out of a molehill

Elmatador,

I think you should look up twos complement on Wikipedia. The explanation is pretty good.

Like I said in my previous post, there is no conversion from integer representation to twos complement. Twos complement *IS* the normal method of representing a signed integer. And, the "twos complement" part only applies to the representation of negative numbers.

Your specific examples in 16-bit format:

200 = 0000 0000 1100 1000 or Hex 00C8
-40 = 1111 1111 1101 1000 or Hex FFD8

This is normal, you put these patterns in a 16-bit integer and the PLC will interpret them as 200 and -40.

Now if you considered the bit pattern for a 16-bit -40 to be unsigned the value in decimal would be 65496. The only difference is how you interpret the bit pattern. If the high bit is on, you have to know if you are looking at a signed or unsigned number to know what it means.
 
Hello Everyone,

Sorry I didnt respond for a while. Was in the field with no email access. So guess what, it turns out that the Controllogix PLC interprets the data as 2-s signed complement. Exactly like how most of you mentioned on this thread. I didn't have to end up doing any conversion. Sorry guys, I am a rookie and still learning.

A value of 200 came in as 200 and a value of -40 came in as -40.

I really appreciate everyone's insight on this topic. I wish we had Thank buttons on this forum so that I could thank you all.
 
elmatador, where did you getting the bit patterns and values you were posting from? When you stated that the value sent from the Multilin was -40 and the CLX interpreted it as 32728 that certainly didn't sound like a 2's complement value.

Keith
 

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,371
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,599
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
396
Back
Top Bottom