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




Bookmarks