How to read SINT (short signed Integer) with CJ2 PLC
Posted 13 September 2012 - 05:40 PM
I can't find an easy way to read that Signed 8 Bit integer value into cx-programmer, using PLC instructions/conversion. I read about the NEG(160) two'd complement but I can't get it to work.
Posted 13 September 2012 - 07:01 PM
Posted 14 September 2012 - 09:06 AM
The easiest way that I can figure to do it would be to use the ANDW function to mask out bits 7-15, leaving the absolute value of the short signed integer. Then look at the sign bit, if it is on, multiply the masked value by -1, if it is off, just move the value as shown below:
Thanks for the reply.
I tried that approach but that doesn't return the correct value...this is what you must get:
for 1111 1111 two's complement value= -1
but using the mask and multiply method you get -127
Unless I am doing something wrong...
Posted 14 September 2012 - 10:24 AM
Posted 14 September 2012 - 02:43 PM
Posted 14 September 2012 - 06:02 PM
Posted 17 September 2012 - 09:15 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users