Top Banner
Chapter 3 Chapter 3 BINARY ARITHMETIC AND TWO’s COMPLEMENT ARITHMETIC
24

BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

Feb 11, 2017

Download

Documents

dinhbao
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

Chapter 3Chapter 3

BINARY ARITHMETIC AND TWO’s COMPLEMENT

ARITHMETIC

Page 2: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

2

Lesson 2

Two’s complement number and binary subtraction

Page 3: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

3

Outline

•• TwoTwo’’s complement s complement • Two’s complement Examples• Binary subtraction

Page 4: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

4

Finding Two’s Complement

• Step 1: First complement all the bits (that is find one’s complement)

Make all 1s as 0s and all 0s as 1s

• Step 2:Then perform increment by 1Add 0001b

Page 5: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

5

Two’s Complement as -ve Number

• Two’s complement is -ve number because binary addition of a n-bit number with it’s complement gives n-bit result with all bits = 0s

Page 6: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

6

Highest Two’s Complement format + ve Number

A highest positive arithmetic number is when at msb there is 0 and all

remaining bits are 1s

Page 7: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

7

Lowest Two’s Complement format −−−− ve Number

A lowest negative arithmetic number is when at msb there is 1 and all

remaining bits are 0s

Page 8: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

8

Arithmetic Numbers

Two’s complement format arithmetic number

• Maximum 8-bit number = 0111 1111( +127)• Minimum 8-bit number = 1000 0000 ( −128)

Page 9: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

9

Arithmetic Numbers

Two’s complement format arithmetic number

• Maximum 16-bit number = 0111 1111 1111 1111( +32767)• Minimum 16-bit number = 1000 0000 0000 0000 ( −32768)

Page 10: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

10

Outline

• Two’s complement •• TwoTwo’’s complement Exampless complement Examples• Binary subtraction

Page 11: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

11

Example

0 1 0 1 [= +5d]One’s Complement 1 0 1 0 Add 0 0 0 1 Sum 1 0 1 1Therefore, Two’s Complement = 1 0 1 1 [It is − 5dbecause 0101 + 1011 = 0.]

Page 12: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

12

Example

Number +16392 0100 0000 0000 1000One’s complement 1011 1111 1111 0111

+ 0000 0000 0000 0001−16392 1011 1111 1111 1000

Page 13: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

13

Prove = 1011 1111 1111 1000 = − 16392

Assume Decimal − 16392 =1011 1111 1111 10000100 0000 0000 0111 One’s Complement0000 0000 0000 0001 Add0100 0000 0000 1000 Two’s Complement

[Since result is = Decimal + 16392, hence assumption is correct.]

Page 14: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

14

Prove 1000 000 0000 0000 = − 32768

0111 1111 1111 1111 [= Decimal + 32767]1000 0000 0000 0000 [one’s Complement ]0000 0000 0000 0001 Add1000 0000 0000 0001 Two’s Complement

[= Decimal − 32767]Now this is 1 more than 1000 000 0000 0001. Thus 1000 000 0000 0000 = − 32768

Page 15: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

15

Outline

• Two’s complement • Two’s complement Examples•• Binary subtractionBinary subtraction

Page 16: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

16

Binary subtraction A −−−− B

• Add A with two’s complement of B to find A − B, provided we use two’s complementation for representation

− ve numbers

Page 17: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

17

Example: Find 129 − 128

0000 0000 1000 0001 [= +129d]1111 1111 1000 0000 [= − 128d]0000 0000 0000 0001 [= + 1d]

Page 18: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

18

Example Find + 16392 −−−− (16392)

A= +16392 0100 0000 0000 1000One’s complement 1011 1111 1111 0111

+ 0000 0000 0000 0001−B= −16392 1011 1111 1111 1000

•Find A + (− B) Answer 0000 0000 0000 0000

Page 19: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

19

Example: Find +1020 −−−− (−−−− 1017)

1111 1100 0000 0111 [−−−− 1017 d]0000 0011 1111 1001 [−−−− (− 1017) d]0000 0011 1111 1100 [= +1020d]0000 0111 1111 0101 [= +2037d]

Page 20: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

20

Example: Find −−−− 1017 −−−− (−−−− 1020)

1111 1100 0000 0111 [−−−− 1017 d]0000 0011 1111 1100 [−−−− (− 1020) d]

0000 0000 0000 0011 [= +3d]

Page 21: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

Summary

Page 22: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

• Two’s complement is found by first finding 1’s complement and then adding 0001b.

• Two’s complement gives negative of a given number

• Adding a number with it’s two’s complement gives all bits = 0s

Page 23: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

End of Lesson 2 on End of Lesson 2 on Two’s complement number Two’s complement number

and binary subtractionand binary subtraction

Page 24: BINARY ARITHMETIC AND TWO's COMPLEMENT ARITHMETIC

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

24

THANK YOU