2-Addition & Subtraction
2-Addition & Subtraction
One’s Complement
• The one’s complement of an integer is obtained by complementing
each bit, that is, replace each 0 by a 1 and each 1 by a 0.
2
2’s Complement
• Negative integers are stored in computer using 2’s complement.
• To get a two’s complement by first finding the one’s complement, and
then by adding 1 to it.
• Example
11110011 (one's complement of 12)
+ 00000001 (decimal 1)
11110100 (two's complement of 12)
3
Subtract
•
as 2’s Complement Addition
Find the difference of 12 – 5 using complementation
and addition.
• 00000101 (decimal 5)
• 11111011 (2’s Complement of 5)
Carry
discard
4
Example
• Find the difference of 5ABCh – 21FCh using complementation and
addition.
• 5ABCh = 0101 1010 1011 1100
• 21FCh = 0010 0001 1111 1100
• 1101 1110 0000 0100 (2’s Complement of 21FCh)