Binary Arithmetic & Negative Numbers
Lecture Outline
• Binary Arithmetic
Addition and subtraction
Multiplication and Division
• Representation of Negative Numbers
1’s compliment, 2’s complement, and sign & magnitude
Number Systems & Conversions
Binary Arithmetic
• Binary Addition
0+0=0
0+1=1+0=1
1 + 1 = 0 and carry 1
• An Example of Binary Addition
1 1 1 1 ← Carries
1101 = 1310
+1011 = 1110
110 00 = 2410
Number Systems & Conversions
Binary Arithmetic
• Binary Subtraction
0-0=0
0 - 1 = 1 and borrow 1
1-0=1
1-1=0
• An Example of Binary Subtraction
0 1 ← Borrows
1 1 1 0 1 = 2910
−10011 = 1910
01010 = 1010
Number Systems & Conversions
Binary Arithmetic
• Binary Multiplication
0X0=0
0X1=1X0=0
1X1=1
• An Example 1101
X1011
= 1310 1101
+1101
= 1110
100111 1st Partial sum
1101 +0000
1101 100111 2nd Partial sum
0000 +1101
1101 Final prod
10001111 = 14310
Number Systems & Conversions
Binary Arithmetic
• Binary Division 1 0 1 1 = 1310
1 101 = 1110
1011 10010001 = 14510
1011
01110
1011
001101
1011
1 0 ← Remainder = 210
Representation of Negative Numbers
• Unsigned Number
bn −1 bn − 2 … b1 b0
Magnitude
MSB LSB
• Signed Number
bn −1 bn − 2 … b1 b0
Magnitude
Sign MSB LSB
Sign bit = 0 ⇒ Number
Sign bit = 1 ⇒ Number
Representation of Negative Numbers
• Three Representations of signed numbers
Sign & Mag, 1’s Complement, and 2’s Complement
• All represent positive numbers in the same way
• How to generate a negative number:
Sign & Mag
Easy for us to read
o Simply change the sign bit
1’s Complement
o Simply flip all of the bits
2’s Complement
o Simply flip all of the bits and add 1
Representation of Negative Numbers
• Three Representations
Sign & Mag, 1’s Complement, and 2’s Complement
Positive Integers Negative Integers
+N All three the -N Sign & 1’s 2’s
Same Magnitude Complement Complement
+0 0000 -0 1000 1111
+1 0001 -1 1001
+2 0010 -2 1010 1101
+3 0011 -3 1011 1100
+4 0100 -4 1100 1100
+5 0101 -5 1010 1011
+6 0110 -6 1110 1001
+7 0111 -7 1111 1000 1001
-8
Representation of Negative Numbers
• Addition and Subtraction
Sign and Magnitude
o Simple if both numbers have the same sign
o More complex if the signs differ
o Two different representations of “0” is problematic
1’s Complement
o Addition and subtraction not so simple
o Two different representations of “0” is problematic
2’s Complement
o Both addition and subtraction are
• Graphical Representation of 2’s Complement Numbers
Largest positive number is +( )
Largest negative number is -( )
− ( 2n−1 ) =
− ( 23 ) =
−8 + ( 2n−1 − 1) =+ ( 23 − 1) =+7
Representation of Negative Numbers
• 2’s Complement Subtraction
Just don’t do it!!
To subtract B from A add A and (-B)
A – B = A + (-B)
Next Lecture
• Extending Numeric Precision
• Binary Codes