Complement Arithmetic in a Nutshell

Unsigned numbers:

Subtraction:

Two's complement:

15
001111
001111
-7
-000111
+111001
8
001000


1
drop 
001000

7
000111
000111
-15
-001111
+110001
-8
-001000
111000


One's complement:

15
001111
001111
-7
-000111
+111000
8
001000


1
add 
000111
+1
001000

7
000111
000111
-15
-001111
+110000
-8
-001000
110111


Signed Numbers:

Signed Two's complement:

Addition:

Add both numbers. If a carry is produced, drop it. The result will be in signed two's complement form

+15
001111
+(-7)
+111001
8


1
drop 
001000

+7
000111
+(-15)
+110001
-8
111000


Subtraction:

Add the minuend to the complement of the subtrahend. If a carry is produced, drop it.

+7
000111
-(-15)
+001111
+22
010110

-14
001110
-(+12)
+001110
-26


1
drop 
100110











Overflow:

Occurs when result requires more bits than the number format can store, i.e., the addition of two unsigned 4-bit numbers can result in a 5-bit number (indicated by a carry out):

10
1010
+8
+1000
18
10010

With signed numbers, overflow is indicated when the carry into the Most significant (leftmost) bit position and out of the MSB position are different.

For instance, consider the addition of the following 2 6-bit signed numbers:

+20
010100
+(+18)
+010010
-26??
100110
-(011010)



File translated from TEX by TTH, version 0.9.