View Full Version : two’s complement
cncmachineguy
- 5th March 2011, 16:27
I have searched the manual and this forum for the two’s complement command. I guess I can't find it or there is none.
So will this do it?
CHKSUM = (CHKSUM REV7)+1
Or is there a way I have not found?
Darrel Taylor
- 6th March 2011, 15:48
There are a couple ways to work with 2's compliment numbers.
"2's compliment" is simply a way to store positive and negative numbers.
You can can change a number to a positive value when it's either positive or negative using the ABS (Absolute Value) function.
PosValue = ABS MyValue
Or, a value can be inverted ... made positive if it's negative, or negative if it's positive using the negative sign.
InvValue = -(MyValue)
That is the same as complimenting the bits and adding 1.
Which can also be done with the bitwise NOT operator (+1).
InvValue = ~(MyValue) + 1
cncmachineguy
- 6th March 2011, 17:13
Ok, thanks Darrel, I will use the last 1. It just looks cool!
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.