Lesson 03 - 2's Complement & Negative Binary Numbers
Lesson 03 - 2's Complement & Negative Binary Numbers
The NINES complement is determined by subtracting each digit in the decimal number from the decimal
digit 9.
Therefore:
Examples:
10 1000 100000
-7 - 319 - 14827
3 681 85173
9 999 99999
-7 - 319 - 14827
2 680 85172
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 1
We can also achieve the same result by adding the TENS complement of the subtrahend and then
subtracting 10n:
The advantage of using this method is that you never need to borrow a place value. Complement
addition replaces binary subtraction in computer arithmetic.
Binary Complements
The ONES complement is determined by subtracting each bit in the binary number from 1. Therefore
the ONES complement of 101010 is:
111111
- 101010
010101
Notice that the ONES complement can be found easily by “flipping” or “switching” each bit.
Since TWOS complement is equivalent to the ONES complement + 1, we can use the following algorithm
to get the TWOS complement of a binary number:
1. Get the ONES complement by “flipping” each bit in the binary number (change all 0’s to 1’s and
all 1’s to 0’s).
2. Add 1 to the ONES complement.
01101010 + 1 = 01101011
110111011 0110001000
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 2
Negative Binary Numbers
How are negative numbers represented and used in a computer?
a) We can dedicate the Most Significant Bit (left-most bit) to indicate the sign of the number
The bits to the left of the most significant bit indicate the number’s magnitude. This is
known as sign-magnitude. This method makes it easy to identify whether a number is
negative, BUT there are two representations of zero and addition does not always work
properly.
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 3
1. Bit Field Length
When working with negative binary numbers it is imperative to pick a bit field length and use that
same length throughout the calculation. Bit field length must be the same for both numbers in the
calculation.
Example:
We decide to use a bit field length of 4 to represent the numbers from -8 (TWOS complement of 8 is
1000) to 7 (0111). The number line for a 4-bit field looks like the following:
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111
When finding the TWOS complement of a number, we use the entire bit field length to calculate the
complement.
0001
+1111
10000
The answer is 10000bin. Since we are using a fixed bit length of 4, we just discard the left-most bit
to get an answer of 0000 or (0) dec.
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 4
Subtracting in the binary number system:
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 5
2. Bit Field Extension
When numbers are the same sign, using a fixed bit length may cause issues. It may be that an extra
bit is required for the correct answer. This is called overflow.
Examples:
0 1 0 1 = 5 1 1 0 0 = - 4
+ 0 1 1 1 = + 7 + 1 0 0 1 = - 7
1 0 0 0 ≠ 12 0 1 0 1 ≠ - 11
Note that the sign of the result is different than the sign of both addends!
1. If two numbers have different signs, their sum will never overflow.
2. If the numbers have the same sign, they might overflow.
3. To deal with overflow we extend the bit field length of the numbers BEFORE the calculation.
If when calculating overflow is occurring, “promote” values to larger bit field lengths. This process is
known as sign extension.
Sign Extension:
Duplicate the value of the most significant bit to the left of the existing bit field
The sign of the number is retained
The value of the number does not change
All values MUST be promoted to the same bit field length BEFORE any calculations.
Exercise 5:
Subtract the following binary numbers using complement math. Watch out for negative results!
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 6
Exercises
1. Subtract the following binary numbers using the complement method and calculate the decimal
equivalent (watch out for negative results!)
a)
00101 − 01111 b)
01011 − 01110
a)
010111 + 01011 b)
01101 + 01100
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 7
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 8
3. Steve bought the following from the Sheridan Department Store:
Shoes for $111011bin
Jacket for $110111bin
Gloves for $1110bin
Socks for $111bin
Calculate the total bill in both binary dollars and decimal dollars.
MATH 18584 Lesson 03: 2’s Complement and Negative Binary Numbers 9