Calculation of 2's Complement Addition Subtraction Multiplication Division Sign Extension Other Signed Representations Notes
Calculation of 2's Complement Addition Subtraction Multiplication Division Sign Extension Other Signed Representations Notes
Definition
Addition
Subtraction
Multiplication
Division
Sign Extension
Notes
Definition
Property
Two's complement representation allows the use of binary arithmetic operations on signed integer
yielding the correct 2's complement results.
Positive Numbers
Positive 2's complement numbers are represented as the simple binary.
Negative Numbers
Negative 2's complement numbers are represented as the binary number that when added to a
positive number of the same magnitude equals zero.
Integer
2's Complement
Signed
Unsigned
0000 0101
0000 0100
0000 0011
0000 0010
0000 0001
0000 0000
-1
255
1111 1111
-2
254
1111 1110
-3
253
1111 1101
-4
252
1111 1100
-5
251
1111 1011
Note: The most significant (leftmost) bit indicates the sign of the integer; therefore it is sometime
called the sign bit.
If the sign bit is zero,
then the number is greater than or equal to zero, or positive.
If the sign bit is one,
then the number is less than zero, or negative.
To calculate the 2's complement of an integer, invert the binary equivalent of the number by
changing all of the ones to zeroes and all of the zeroes to ones (also called 1's complement), and
then add one.
For example,
0001 0001(binary 17)
NOT(0001 0001)
0000 0101
+5
+ 1111 1101
-3
0000 0010
+2
Two's complement subtraction is the binary addition of the minuend to the 2's complement of th
subtrahend (adding a negative number is the same as subtracting a positive one).
For example,
7 - 12 = (-5)
0000 0111
+7
+ 1111 0100
-12
1111 1011
-5
1111 1100
-4
0000 0100
+4
1111 0000
-16
Two's complement division is repeated 2's complement subtraction. The 2's complement of the
divisor is calculated, then added to the dividend. For the next subtraction cycle, the quotient repla
the dividend. This repeats until the quotient is too small for subtraction or is zero, then it becomes
the remainder. The final answer is the total of subtraction cycles plus the remainder.
For example,
7 3 = 2 remainder 1
0000 0111
= +7
0000 0100
= +4
+ 1111 1101
= -3
+ 1111 1101
0000 0100
= +4
0000 0001
= -3
= +1 (remainder)
Sign Extension
To extend a signed integer from 8 bits to 16 bits or from 16 bits to 32 bits, append additional bits o
the left side of the number. Fill each extra bit with the value of the smaller number's most significa
bit (the sign bit).
For example,
Signed Integer
8-bit Representation
16-bit Representation
-1
1111 1111
+1
0000 0001
For example,
Sign Magnitude
Offset Binary
+5
0000 0101
1000 0101
+4
0000 0100
1000 0100
+3
0000 0011
1000 0011
+2
0000 0010
1000 0010
+1
0000 0001
1000 0001
0000 0000
1000 0000
1000 0000
-1
1000 0001
0111 1111
-2
1000 0010
0111 1110
-3
1000 0011
0111 1101
-4
1000 0100
0111 1100
-5
1000 0101
0111 1011
Notes
Other Complements
1's Complement = NOT(n) = 1111 1111 - n
Binary Arithmetic
Addition
Subtraction
Multiplication
Division