Negation
In sign-magnitude representation, the rule for forming the negation of an integer is simple: Invert the sign bit.
In twos complement representation, the negation of an integer can he formed with the following rules:
1. Take the Boolean complement of each bit of the integer (including the sign bit). That is. set each 1 to 0 and each 0 to 1.
2. Treating the result as an unsigned binary integer, add 1.
This two-step process is referred to as the twos complement operation, or the taking of the twos complement of an integer
Example:
Figure 2
Negation Special Case 1:
0 = 00000000
Bitwise not 11111111
Add 1 to LSB +1
Result 1 00000000
Overflow is ignored, so: - 0 = 0
Negation Special Case 2:
-128 = 10000000
bitwise not 01111111
Add 1 to LSB +1
Result 10000000
So: -(-128) = -128.
Because 128 is out of the range of signed 8bits numbers.
Addition and Subtraction:
Addition and Subtraction is done using following steps:
Normal binary addition
Monitor sign bit for overflow
Take twos compliment of subtrahend and add to minuend ,i.e. a - b = a + (-b)