arithmetic two’s complement binary …1101 b). step 1: p0 = x x x x 1 0 1 0 step 2: p1 = x x x 0 0...

30
Chapter 3 Chapter 3 BINARY ARITHMETIC AND TWO’s COMPLEMENT ARITHMETIC

Upload: lekhuong

Post on 17-May-2018

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Chapter 3Chapter 3

BINARY ARITHMETIC AND TWO’s COMPLEMENT

ARITHMETIC

Page 2: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

2

Lesson 3

BINARY MULTIPLICATION AND DIVISION

Page 3: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

3

Outline

•• MultiplicationMultiplication: Unsigned Numbers•• MultiplicationMultiplication: Signed Numbers• Division

Page 4: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

4

Multiplication of 1-bit ×××× 1-bit

• Dot operator represents an AND operation. AND operations.

• 1. 1 = 1 …..(1)• 1. 0 = 0 …..(2)• 0. 1 = 0 …..(3)• 0. 0 = 0 …..(4)

Page 5: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

5

Multiplication of n-bit ×××× 1-bit

• Perform AND operation on all n-bits with the multiplying bit

• Multiplication by 1b gives same number as before

Example 1: 1 0 1 1 ×××× 1

Using Equations (1) and (2)Answer is 1 0 1 1

Page 6: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

6

Multiplication of n-bit ×××× 1-bit

Multiplication by 0b gives all 0s.Example 2: 1 0 1 1

×××× 0Using Equations (1) and (2)Answer is 0 0 0 0

Page 7: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

7

Shift left operation by 1-bit

Example 3: 1 0 1 1 Shift Left

Answer is 0110.(Place of each bit moves to left and msb

is discarded.)

Page 8: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

8

Shift left operation by 2-bit

Example 3: 1 0 1 1 Shift Left Twice

Answer is shift once 0110. Shift again 1100

Page 9: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

9

Multiplication of n-bit ×××× m-bit

Step1: Find P0 Multiple n-bit by rightmost 1-bit

Steps 2 and 3: Find P1 Multiple n-bit by rightmost but 1-bit and shift left once and add with P0 and find S0

Steps 4 and 5: Find P2 Multiple n-bit by rightmost but 2-bits and shift left 2 times, add by S0. and find S1

Page 10: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

10

Multiplication of n-bit ×××× m-bit

Continue till all m-bits are multipliedand sum of partial products P0 + P1 + Pm-1 is

found

Page 11: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

11

Example: multiplicand = 10d (1010b)and multiplier = 13d (1101b).

Step 1: P0 = x x x x 1 0 1 0Step 2: P1 = x x x 0 0 0 0 _---------------------------------Step 3 S0 = x x 0 0 1 0 1 0Step 4 P2 = x x 1 0 1 0 _ _

Page 12: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

12

Example: multiplicand = 10d (1010b)and multiplier = 13d (1101b).

Step 5 S1 = x 0 1 1 0 0 1 0Step 6 P3 = x 1 0 1 0 _ _ _------------------------------------Step 7 S2 = 1 0 0 0 0 0 1 0----------------------------------M = 1 0 0 0 0 0 1 0 = Decimal 130d

Page 13: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

13

Outline

•• MultiplicationMultiplication: Unsigned Numbers•• MultiplicationMultiplication: Signed Numbers• Division

Page 14: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

14

Signed Numbers

For multiplication use msb as sign bit and remaining bits for a

positive number

Page 15: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

15

Signed Multiplication of n-bit ×××× m-bit

Step1: Find P0 Leave msb and Multiple n−1 bits by rightmost 1-bit

Steps 2 and 3: Find P1 Multiple n−1 bits by rightmost but 1-bit and shift left once and add with P0 and find S0

Steps 4 and 5: Find P2 Multiple n−1 bits by rightmost but 2-bits and shift left 2 times, add by S0. and find S1

Page 16: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

16

Multiplication of n-bit ×××× m-bit

Continue till all (m −1) bits are multipliedand sum P0 + P1 + Pm-2 is foundNow find the sign bit msb of the result• If both msb = 0s, then msb of product = 0• If msbs = 1 and 0, then msb of product = 1• If both msb = 1s, then msb of product = 0

Page 17: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

17

Example: multiplicand = 10d (1010b)and multiplier = 13d (1101b).

Step 1: P0 = x x x x 1 0 1 0Step 2: P1 = x x x 0 0 0 0 _---------------------------------Step 3 S0 = x x 0 0 1 0 1 0Step 4 P2 = x x 1 0 1 0 _ _

Page 18: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

18

Example: multiplicand = 10d (1010b)and multiplier = 13d (1101b).

Step 5 S1 = x 0 1 1 0 0 1 0Step 6 P3 = x 1 0 1 0 _ _ _------------------------------------Step 7 S2 = 1 0 0 0 0 0 1 0----------------------------------M = 1 0 0 0 0 0 1 0 = Decimal 130d

Page 19: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

19

Outline

• Multiplication: Unsigned Numbers•• MultiplicationMultiplication: Signed Numbers•• DivisionDivision

Page 20: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

20

Binary Division

• Binary arithmetic division isby successive subtraction

Page 21: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

21

Division Method

Let dividend by X and divisor be Y. When we divide the unsigned format number (integers non fractional numbers)

Page 22: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

22

Division Method

1. Set the initial quotient = 0000. 2.Check if X < Y, if yes, then Q is unchanged and R = X. Stop the process.

3.If X > Y, increment the quotient. [New Q in first cycle is = 0001, second cycle it will be 0010.]

Page 23: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

23

Division Method

4. Find X – Y using two’s complement arithmetic and get the R.5. Set X = R.Repeat steps 2 to 5 till X <

Y.6. Now Q is the result for the quotient

and R =finally left X is the final remainder

Page 24: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

24

Example X ÷ Y = 0111 ÷ 0011

Here X > Y.tap 1: Q = 0000Step 2: X > Y and so go to next step.Step 3: Q = 0001Step 4: Find X – Y = 0111 – 0011 = 0111 +

1101 = 0100. R = 0100.Step 5: X = R = 0100.

Page 25: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

25

Example X ÷ Y = 0111 ÷ 0011

Step 6: Repeat steps 2 to 5. We get Q = 0001 + 1 = 0010 and R = 0001.

Answer is Q = 0010 (decimal 2) and R = 0001 (decimal 1) as expected from division of 7 by 3

Page 26: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

26

Division of Signed numbers

• Divide (n −1) bits leaving msbs of X and Y• Now find the sign bit msb of the quotient• If both msb = 0s, then msb of quotient = 0• If msbs = 1 and 0, then msb of quotient = 1• If both msb = 1s, then msb of quotient = 0

Page 27: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Summary

Page 28: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

• Multiplication is found by 1-bit multiplications, finding partial products, shift left the partial products and find the sum

• Division is by repeated subtraction

• Use signed number in multiplication and division

Page 29: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

End of Lesson 2 on End of Lesson 2 on BINARY

MULTIPLICATION AND DIVISION

Page 30: ARITHMETIC TWO’s COMPLEMENT BINARY …1101 b). Step 1: P0 = x x x x 1 0 1 0 Step 2: P1 = x x x 0 0 0 0 _-----Step 3 S0 = x x 0 0 1 0 1 0 ... Binary Division • Binary arithmetic

Ch03L3-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006

30

THANK YOU