243 2s Complement Arithmkhkhjketic
243 2s Complement Arithmkhkhjketic
243 2s Complement Arithmkhkhjketic
Digital Electronics
2s Complement Arithmetic
This presentation will demonstrate That subtracting one number from another is the same as making one number negative and adding. How to create negative numbers in the binary number system. The 2s Complement Process. How the 2s complement process can be use to add (and subtract) binary numbers.
2
Negative Numbers?
Digital electronics requires frequent addition and subtraction of numbers. You know how to design an adder, but what about a subtract-er? A subtract-er is not needed with the 2s complement process. The 2s complement process allows you to easily convert a positive number into its negative equivalent. Since subtracting one number from another is the same as making one number negative and adding, the need for a subtract-er circuit has been eliminated.
forward (+)
002 001
backward (-)
5
Negative Decimal
How do we represent negative numbers in this 3digit decimal number system without using a sign?
Cut the number system in half. Use 001 499 to indicate positive numbers. Use 500 999 to indicate negative numbers. Notice that 000 is not positive or negative.
+499 +498 +497 499 498 497
pos(+)
-499 -500
501 500
neg(-)
6
6 + (-3)
3
(-5) + 2 (-3)
(-2) + (-3)
(-5)
998 + 997
1995
Disregard Overflow
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 10s Complement Process.
8
Second, add 1.
Without this step, our number system would have two zeroes (+0 & -0), which no number system has.
9
Complement Digits
Add 1
Example #2
Complement Digits
Add 1
10
pos(+)
+1 0 -1 -2
-127 -128
10000001 10000000
neg(-)
11
Sign Bit
What did do you notice about the most significant bit of the binary numbers? The MSB is (0) for all positive numbers. The MSB is (1) for all negative numbers. The MSB is called the sign bit. In a signed number system, this allows you to instantly determine whether a number is positive or negative.
+127 +126 +125 01111111 01111110 01111101
pos(+)
+1 0 -1 -2
-127 -128
10000001 10000000
neg(-)
12
2S Complement Process
The steps in the 2s Complement process are similar to the 10s Complement process. However, you will now use the base two. First, complement all of the digits in a number.
A digits 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
2s Complement Examples
Example #1
5 = 00000101 11111010
+1 Complement Digits
-5 = 11111011
Add 1
Example #2
-13 = 11110011 00001100
+1
Complement Digits
13 = 00001101
Add 1
14
9 + 5 14
(-9) + 5 -4
9 + (-5) 4
(-9) + (-5) - 14
15
9 + 5 14
16
9 + (-5) 4
2s Complement Process
17
(-9) + 5 -4
11111100 00000011 +1 00000100
2s Complement Process
18
19