Lecture No. 06
Computer Arithmetic
Introduction
• ADDITION
– Like decimal numbers, two numbers can be
added by adding each pair of digits together
with carry propagation.
(647)10
+ (537)10
(1184)10
Binary Addition
• Two 1-bit values
A B A + B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Binary Addition
• Two n-bit values
– Add individual bits
– Propagate carries
– E.g.,
10101 21
+ 11001 + 25
101110 46
11
Try it: 0011 + 1010
1 1 1 1 0 1
+ 1 0 1 1 1
---------------------
0
1
0
1
1
1111
1 1 00
carries
Example Add (11110)2 to
(10111)2
carry
Binary Addition
Negative Numbers Representation
 Unsigned numbers: only non-negative values.
 Signed numbers: include all values (positive and negative).
 Till now, we have only considered how unsigned (non-
negative) numbers can be represented. There are three
common ways of representing signed numbers (positive and
negative numbers) for binary numbers:
 Sign-and-Magnitude
 1s Complement
 2s Complement
Negative Numbers:
Sign-and-Magnitude
 Negative numbers are usually written by writing a
minus sign in front.
 Example:
– - (12)10 , - (1100)2
 In sign-and-magnitude representation, this sign is
usually represented by a bit:
– 0 for +
– 1 for -
Negative Numbers:
Sign-and-Magnitude
 Example: an 8-bit number can have 1-bit sign and 7-bit
magnitude.
sign magnitude
Negative Numbers:
Sign-and-Magnitude
 Largest Positive Number: 0 1111111 +(127)10
 Largest Negative Number: 1 1111111 -(127)10
 Zeroes: 0 0000000 +(0)10
1 0000000 -(0)10
 Range: -(127)10 to +(127)10
Compliments
• Subtraction in any number system can be accomplished
through the use of complements.
• A complement is a number that is used to represent the
negative of a given number.
1s and 2s Complement
 Two other ways of representing signed numbers
for binary numbers are:
 1s-complement
 2s-complement
Complementary Arithmetic
• 1’s complement
– Switch all 0’s to 1’s and 1’s to 0’s
Binary # 10110011
1’s complement 01001100
Complementary Arithmetic
• 2’s complement
– Step 1: Find 1’s complement of the number
Binary # 11000110
1’s complement 00111001
– Step 2: Add 1 to the 1’s complement
00111001
+ 00000001
00111010
2’s Complement Examples
Example #1
Complement Digits
Add 1
5 = 00000101
-5 = 11111011

11111010
+1
2’s Complement Examples
Complement Digits
Add 1
-13 = 11110011
13 = 00001101

00001100
+1
Using The 2’s Compliment Process
9
+ (-5)
4
(-9)
+ 5
- 4
(-9)
+ (-5)
- 14
9
+ 5
14
POS
+ POS
POS

POS
+ NEG
POS

NEG
+ POS
NEG

NEG
+ NEG
NEG

Use the 2’s complement process to add together the
following numbers.
POS + POS → POS Answer
If no 2’s complement is needed, use regular binary addition.
000010019
+ 5
14

 00001110
00000101 +
POS + NEG → POS Answer
Take the 2’s complement of the negative number and use
regular binary addition.
000010019
+ (-5)
4


11111011+
00000101

11111010
+1
11111011
2’s
Complement
Process
1]00000100
8th Bit = 0: Answer is Positive
Disregard 9th Bit
POS + NEG → NEG Answer
Take the 2’s complement of the negative number and use
regular binary addition.
11110111(-9)
+ 5
-4


00000101+
00001001

11110110
+1
11110111
2’s
Complement
Process
11111100
8th Bit = 1: Answer is Negative
11111100

00000011
+1
00000100
To Check:
Perform 2’s
Complement
On Answer
NEG + NEG → NEG Answer
Take the 2’s complement of both negative numbers and use
regular binary addition.
11110111(-9)
+ (-5)
-14


11111011 +
2’s Complement
Numbers, See
Conversion Process
In Previous Slides
1]11110010
8th Bit = 1: Answer is Negative
Disregard 9th Bit
11110010

00001101
+1
00001110
To Check:
Perform 2’s
Complement
On Answer
Thank you

Lecture 06 computer arithmatic

  • 1.
  • 2.
    Introduction • ADDITION – Likedecimal numbers, two numbers can be added by adding each pair of digits together with carry propagation. (647)10 + (537)10 (1184)10
  • 3.
    Binary Addition • Two1-bit values A B A + B 0 0 0 0 1 1 1 0 1 1 1 10 “two”
  • 4.
    Binary Addition • Twon-bit values – Add individual bits – Propagate carries – E.g., 10101 21 + 11001 + 25 101110 46 11
  • 5.
  • 6.
    1 1 11 0 1 + 1 0 1 1 1 --------------------- 0 1 0 1 1 1111 1 1 00 carries Example Add (11110)2 to (10111)2 carry Binary Addition
  • 7.
    Negative Numbers Representation Unsigned numbers: only non-negative values.  Signed numbers: include all values (positive and negative).  Till now, we have only considered how unsigned (non- negative) numbers can be represented. There are three common ways of representing signed numbers (positive and negative numbers) for binary numbers:  Sign-and-Magnitude  1s Complement  2s Complement
  • 8.
    Negative Numbers: Sign-and-Magnitude  Negativenumbers are usually written by writing a minus sign in front.  Example: – - (12)10 , - (1100)2  In sign-and-magnitude representation, this sign is usually represented by a bit: – 0 for + – 1 for -
  • 9.
    Negative Numbers: Sign-and-Magnitude  Example:an 8-bit number can have 1-bit sign and 7-bit magnitude. sign magnitude
  • 10.
    Negative Numbers: Sign-and-Magnitude  LargestPositive Number: 0 1111111 +(127)10  Largest Negative Number: 1 1111111 -(127)10  Zeroes: 0 0000000 +(0)10 1 0000000 -(0)10  Range: -(127)10 to +(127)10
  • 11.
    Compliments • Subtraction inany number system can be accomplished through the use of complements. • A complement is a number that is used to represent the negative of a given number.
  • 12.
    1s and 2sComplement  Two other ways of representing signed numbers for binary numbers are:  1s-complement  2s-complement
  • 13.
    Complementary Arithmetic • 1’scomplement – Switch all 0’s to 1’s and 1’s to 0’s Binary # 10110011 1’s complement 01001100
  • 14.
    Complementary Arithmetic • 2’scomplement – Step 1: Find 1’s complement of the number Binary # 11000110 1’s complement 00111001 – Step 2: Add 1 to the 1’s complement 00111001 + 00000001 00111010
  • 15.
    2’s Complement Examples Example#1 Complement Digits Add 1 5 = 00000101 -5 = 11111011  11111010 +1
  • 16.
    2’s Complement Examples ComplementDigits Add 1 -13 = 11110011 13 = 00001101  00001100 +1
  • 17.
    Using The 2’sCompliment Process 9 + (-5) 4 (-9) + 5 - 4 (-9) + (-5) - 14 9 + 5 14 POS + POS POS  POS + NEG POS  NEG + POS NEG  NEG + NEG NEG  Use the 2’s complement process to add together the following numbers.
  • 18.
    POS + POS→ POS Answer If no 2’s complement is needed, use regular binary addition. 000010019 + 5 14   00001110 00000101 +
  • 19.
    POS + NEG→ POS Answer Take the 2’s complement of the negative number and use regular binary addition. 000010019 + (-5) 4   11111011+ 00000101  11111010 +1 11111011 2’s Complement Process 1]00000100 8th Bit = 0: Answer is Positive Disregard 9th Bit
  • 20.
    POS + NEG→ NEG Answer Take the 2’s complement of the negative number and use regular binary addition. 11110111(-9) + 5 -4   00000101+ 00001001  11110110 +1 11110111 2’s Complement Process 11111100 8th Bit = 1: Answer is Negative 11111100  00000011 +1 00000100 To Check: Perform 2’s Complement On Answer
  • 21.
    NEG + NEG→ NEG Answer Take the 2’s complement of both negative numbers and use regular binary addition. 11110111(-9) + (-5) -14   11111011 + 2’s Complement Numbers, See Conversion Process In Previous Slides 1]11110010 8th Bit = 1: Answer is Negative Disregard 9th Bit 11110010  00001101 +1 00001110 To Check: Perform 2’s Complement On Answer
  • 22.

Editor's Notes

  • #16 Examples of the 2’s Complement Process.
  • #17 Examples of the 2’s Complement Process.
  • #18 This slide show that there are only four possible combinations for adding together two signed numbers. The next four slides demonstrate each of these examples.
  • #19 Addition of two Positive numbers.
  • #20 This example shows the addition of one positive and one negative numbers. Note that this is done in the same way as subtracting a positive number from a positive number. In this case, the answer is positive.
  • #21 This slide demonstrates the addition of one positive and one negative number. Again, this is is the same a subtracting a positive number from a positive number. In this case the answer happens to be negative.
  • #22 This slide demonstrates the addition of two negative numbers.