You are on page 1of 19

2’s Complement Arithmetic

1
1's Complement Representation
• Positive numbers are represented using normal binary
equivalent while negative numbers are represented by
the 1's complement (complement) of the normal binary
representation of the magnitude.
+9 is represented as 01001

-9 is represented as 10110 (obtained by complementing


the binary representation of 9).

Important Note: Negative numbers will always have a 1


in the MSB while positive numbers will have a 0 in the
MSB.
2's Complement Representation
• Positive numbers are represented using normal binary
equivalent while negative numbers are represented by
the 2's complement (complement) of the normal binary
representation of the magnitude. The 2's complement of
a binary number equals its 1's complement + 1.
+9 is represented as 01001

-9 is represented as 10111 (Now leave the LSB 1


unchanged and complement all the remaining bits).
How To Create A Negative Number
• In digital electronics you cannot simply put a
minus sign in front of a number to make it
negative.
• You must represent a negative number in a fixed-
length binary number system. All signed
arithmetic must be performed in a fixed-length
number system.
• A physical fixed-length device (usually memory)
contains a fixed number of bits (usually 4-bits, 8-
bits, 16-bits) to hold the number.

4
3-Digit Decimal Number System
A bicycle odometer with only 999
forward (+)
three digits is an example of a 998
fixed-length decimal number 997
system.
001
The problem is that without a
000
negative sign, you cannot tell
999
a +998 from a -2 (also a 998).
998
Did you ride forward for 998
miles or backward for 2 miles?
002
backward (-)
001
5
Negative Decimal
+499 499
How do we represent pos(+)
negative numbers in this 3- +498 498

digit decimal number system +497 497

without using a sign?


+001 001
Cut the number system in half.
000 000
Use 001 – 499 to indicate
-001 999
positive numbers.
-002 998
Use 500 – 999 to indicate
negative numbers.
-499 501
Notice that 000 is not positive neg(-)
-500 500
or negative.
6
“Odometer” Math Examples
3 003 6 006
+ 2 + 002 + (-3) + 997
5 005 3 1003
Disregard
Overflow

(-5) 995 (-2) 998


+ 2 + 002 + (-3) + 997
(-3) 997 (-5) 1995
Disregard
Overflow
It Works! 7
Complex Problems
• The previous examples demonstrate that this
process works, but how do we easily convert a
number into its negative equivalent?
• In the examples, converting the negative
numbers into the 3-digit decimal number system
was fairly easy. To convert the (-3), you simply
counted backward from 1000 (i.e., 999, 998,
997).
• This process is not as easy for large numbers
(e.g., -214 is 786). How did we determine this?
• To convert a large negative number, you can use
the 10’s Complement Process. 8
10’s Complement Process
The 10’s Complement process uses base-10
(decimal) numbers. Later, when we’re working with
base-2 (binary) numbers, you will see that the 2’s
Complement process works in the same way.
First, complement all of the digits in a number.
– A digit’s complement is the number you add to the digit to
make it equal to the largest digit in the base (i.e., 9 for
decimal). The complement of 0 is 9, 1 is 8, 2 is 7, etc.
Second, add 1.
– Without this step, our number system would have two
zeroes (+0 & -0), which no number system has.
9
10’s Complement Examples
Example #1
-003
Complement Digits

996
+1 Add 1
997
Example #2
-214
Complement Digits

785
+1 Add 1 10
786
8-Bit Binary Number System
Apply what you have learned to the +127 01111111
binary number systems. How do you pos(+)
+126 01111110
represent negative numbers in this 8-bit
+125 01111101
binary system?

Cut the number system in half. +1 00000001


0 00000000
Use 00000001 – 01111111 to indicate
-1 11111111
positive numbers.
-2 11111110
Use 10000000 – 11111111 to indicate
negative numbers. -127 10000001
neg(-)
-128 10000000
Notice that 00000000 is not positive or
11
negative.
Sign Bit
• What did do you notice about the
+127 01111111
most significant bit of the binary pos(+)
+126 01111110
numbers?
+125 01111101
• The MSB is (0) for all positive
numbers. +1 00000001
• The MSB is (1) for all negative 0 00000000
numbers. -1 11111111

• The MSB is called the sign bit. -2 11111110

• In a signed number system, this


-127 10000001
allows you to instantly determine neg(-)
-128 10000000
whether a number is positive or
12
negative.
2’S Complement Process
The steps in the 2’s Complement process are similar
to the 10’s Complement process. However, you will
now use the base two.
First, complement all of the digits in a number.
– A digit’s complement is the number you add to the digit to
make it equal to the largest digit in the base (i.e., 1 for
binary). In binary language, the complement of 0 is 1, and
the complement of 1 is 0.
Second, add 1.
– Without this step, our number system would have two
zeroes (+0 & -0), which no number system has.
13
2’s Complement Examples
Example #1
5 = 00000101
Complement Digits

11111010
+1
Add 1
-5 = 11111011

Example #2
-13 = 11110011
Complement Digits

00001100
+1
Add 1
14
13 = 00001101
Using The 2’s Compliment Process
Use the 2’s complement process to add together
the following numbers.

POS 9 NEG (-9)


+ POS + 5 + POS  + 5
POS 14 NEG -4

POS 9 NEG (-9)


+ NEG  + (-5) + NEG  + (-5)
POS 4 NEG - 14 15
POS + POS → POS Answer
If no 2’s complement is needed, use regular binary
addition.

9  00001001
+ 5  + 00000101
14  00001110

16
POS + NEG → POS Answer
Take the 2’s complement of the negative number and
use regular binary addition.

9  00001001
+ (-5) + 11111011
4  1]00000100
8th Bit = 0: Answer is Positive
Disregard 9th Bit

00000101
 2’s
11111010 Complement
Process
+1
11111011 17
NEG + POS → NEG Answer
Take the 2’s complement of the negative number and
use regular binary addition.

(-9) 11110111
+ 5  + 00000101
-4  11111100
8th Bit = 1: Answer is Negative

11111100 00001001
To Check:   2’s
Perform 2’s Complement
Complement 00000011 11110110
Process
On Answer +1 +1
00000100 11110111 18
NEG + NEG → NEG Answer
Take the 2’s complement of both negative numbers and
use regular binary addition.
2’s Complement
(-9)  11110111 Numbers, See
Conversion Process

+ (-5)  + 11111011 In Previous Slides

-14  1]11110010
8th Bit = 1: Answer is Negative
Disregard 9th Bit

11110010
To Check: 
Perform 2’s
Complement 00001101
On Answer +1
00001110 19

You might also like