Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous...

43
Number Systems Logic Design

Transcript of Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous...

Page 1: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

NumberSystems

LogicDesign

Page 2: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

DigitalSystems

• Digitaldiscipline– Discretevoltagesinsteadofcontinuous– Simplertodesignthananalogcircuits• canbuildmoresophisticatedsystems

– Digitalsystemsreplacinganalogpredecessors• i.e.,digitalcameras,digitaltelevision,cellphones,CDs

2

Page 3: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

TheDigitalAbstraction

• Mostphysicalvariablesarecontinuous– Voltageonawire– Frequencyofanoscillation– Positionofamass

• Digitalabstractionconsidersdiscretesubsetofvalues

3

Page 4: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

TheAnalyticalEngine

• DesignedbyCharlesBabbagefrom1834–1871– Consideredtobethefirstdigitalcomputer

• Builtfrommechanicalgears,whereeachgearrepresentedadiscretevalue(0-9)– Babbagediedbeforeitwasfinished

4

Page 5: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

DigitalDiscipline:BinaryValues

•  Twodiscretevalues:– 1’sand0’s– 1,TRUE,HIGH– 0,FALSE,LOW

•  1and0:voltagelevels,rotatinggears,fluidlevels,etc.•  Digitalcircuitsusevoltagelevelstorepresent1and0•  Bit:Binarydigit

5

Page 6: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Introducedbinaryvariables•  Introducedthethreefundamentallogic operations: AND, OR, andNOT

GeorgeBoole,1815-1864

6

Page 7: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

NumberSystems

•  Decimalnumbers

•  Binarynumbers

537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100

fivethousands

10's column

100's column

1000's column

threehundreds

seventens

fourones

1's column

11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 1310oneeight

2's column

4's column

8's column

onefour

notwo

oneone

1's column

7

Page 8: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  20=1•  21=2•  22=4•  23=8•  24=16•  25=32•  26=64•  27=128

•  28=256•  29=512•  210=1024•  211=2048•  212=4096•  213=8192•  214=16384•  215=32768

PowersofTwo

8

Page 9: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Binarytodecimalconversion:–  Convert100112todecimal

•  Decimaltobinaryconversion:–  Convert4710tobinary

NumberConversion

9

Page 10: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Binarytodecimalconversion:–  Convert100112todecimal–  16×1+8×0+4×0+2×1+1×1=1910

•  Decimaltobinaryconversion:–  Convert4710tobinary–  32×1+16×0+8×1+4×1+2×1+1×1=1011112

NumberConversion

10

Page 11: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Twomethods:o  Method1:Findthelargestpowerof2thatfits,

subtractandrepeato  Method2:Repeatedlydivideby2,remaindergoes

innextmostsignificantbit

DecimaltoBinaryConversion

11

Page 12: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

Method1:Findthelargestpowerof2thatfits,subtractandrepeat5310

Method2:Repeatedlydivideby2,remaindergoesinnextmostsignificantbit5310

DecimaltoBinaryConversion

12

Page 13: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

Method1:Findthelargestpowerof2thatfits,subtractandrepeat5310 32×153-32=21 16×121-16=5 4×15-4=1 1×1

=1101012Method2:Repeatedlydivideby2,remaindergoesinnextmostsignificantbit

5310= 53/2=26R1 26/2=13R0

13/2=6R1 6/2=3R0 3/2=1R1 1/2=0R1 =1101012

DecimaltoBinaryConversion

13

Page 14: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

Anotherexample:Convert7510tobinary.7510=64+8+2+1=10010112

or

75/2 =37R137/2 =18 R118/2 =9 R09/2 =4 R14/2 =2 R02/2 =1 R01/2 =0 R1

DecimaltoBinaryConversion

14

Page 15: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

BinaryValuesandRange

•  N-digitdecimalnumber– Howmanyvalues?– Range?– Example:3-digitdecimalnumber:

•  N-bitbinarynumber– Howmanyvalues?– Range:– Example:3-digitbinarynumber:

15

Page 16: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

BinaryValuesandRange

•  N-digitdecimalnumber– Howmanyvalues?10N– Range?[0,10N-1]– Example:3-digitdecimalnumber:•  103=1000possiblevalues• Range:[0,999]

•  N-bitbinarynumber– Howmanyvalues?2N– Range:[0,2N-1]– Example:3-digitbinarynumber:•  23=8possiblevalues• Range:[0,7]=[0002to1112]

16

Page 17: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

HexDigit DecimalEquivalent BinaryEquivalent0 0 0000

1 1 0001

2 2 0010

3 3 0011

4 4 0100

5 5 0101

6 6 0110

7 7 0111

8 8 1000

9 9 1001

A 10 1010

B 11 1011

C 12 1100

D 13 1101

E 14 1110

F 15 1111

HexadecimalNumbers

Shorthandforbinary(Base16)

17

Page 18: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Hexadecimaltobinaryconversion:–  Convert4AF16(alsowritten0x4AF)tobinary

•  Hexadecimaltodecimalconversion:–  Convert0x4AFtodecimal

HexadecimaltoBinaryConversion

18

Page 19: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Hexadecimaltobinaryconversion:–  Convert4AF16(alsowritten0x4AF)tobinary–  0100101011112

•  Hexadecimaltodecimalconversion:–  Convert4AF16todecimal–  162×4+161×10+160×15=119910

HexadecimaltoBinaryConversion

19

Page 20: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

Bits,Bytes,Nibbles…

• Bits• Bytes&Nibbles• Bytes

10010110nibble

byte

CEBF9AD7least

significantbyte

mostsignificantbyte

10010110least

significantbit

mostsignificant

bit

20

Page 21: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

LargePowersofTwo

• 210=1kilo ≈1000(1024)• 220=1mega ≈1million(1,048,576)• 230=1giga≈1billion(1,073,741,824)

21

Page 22: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

EstimatingPowersofTwo

• Whatisthevalueof224?• Howmanyvaluescana32-bitvariablerepresent?

22

Page 23: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

EstimatingPowersofTwo

• Whatisthevalueof224?24×220≈16million• Howmanyvaluescana32-bitvariablerepresent?22×230≈4billion

23

Page 24: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

Addition

•  Decimal

•  Binary

37345168+

10110011+

24

Page 25: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

Addition

•  Decimal

•  Binary

37345168+8902

carries 11

10110011+1110

11 carries

25

Page 26: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

BinaryAdditionExamples

•  Addthefollowing4-bitbinarynumbers

•  Addthefollowing4-bitbinarynumbers

10010101+

10110110+

26

Page 27: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

BinaryAdditionExamples

•  Addthefollowing4-bitbinarynumbers

•  Addthefollowing4-bitbinarynumbers

10010101+1110

1

10110110+10001

111

Overflow!27

Page 28: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Digitalsystemsoperateonafixednumberofbits

• Overflow:whenresultistoobigtofitintheavailablenumberofbits

Overflow

28

Page 29: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

• Wehavetworepresentation:•  Sign/MagnitudeNumbers•  Two’sComplementNumbers

SignedBinaryNumbers

29

Page 30: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  1signbit,N-1magnitudebits

•  Signbitisthemostsignificant(left-most)bit–  Positivenumber:signbit=0–  Negativenumber:signbit=1

Sign/MagnitudeNumbers

30

Page 31: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Example,4-bitsign/magrepresentationsof±6:+6=0110

-6=1110•  RangeofanN-bitsign/magnitudenumber: [-(2N-1-1),2N-1-1]

Sign/MagnitudeNumbers

31

Page 32: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

Problems:•  Additiondoesn’twork,forexample-6+6:

1110+011010100(wrong!)

•  Tworepresentationsof0(±0):

10000000

Sign/MagnitudeNumbers

32

Page 33: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Don’thavesameproblemsassign/magnitudenumbers:– Additionworks– Singlerepresentationfor0

Two’sComplementNumbers

33

Page 34: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  msbhasvalueof-2N-1

•  Mostpositive4-bitnumber:0111•  Mostnegative4-bitnumber:1000•  Themostsignificantbitstillindicatesthesign(1=negative,0=positive)

•  RangeofanN-bittwo’scomplementnumber:[-(2N-1),2N-1-1]

+

Two’sComplementNumbers

34

Page 35: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  “TakingtheTwo’scomplement”flipsthesignofatwo’scomplementnumber

•  Method:1.  Invertthebits2.  Add1

•  Example:Flipthesignof310=001121.   11002.   +11101=-310

“TakingtheTwo’sComplement”

35

Page 36: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Takethetwo’scomplementof610=01102

•  Whatisthedecimalvalueofthetwo’scomplementnumber10012?

Two’sComplementExamples

36

Page 37: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Takethetwo’scomplementof610=011021.  10012.  +110102=-610

•  Whatisthedecimalvalueofthetwo’scomplementnumber10012?

1.  01102.  +101112=710,so10012=-710

Two’sComplementExamples

37

Page 38: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Add6+(-6)usingtwo’scomplementnumbers

•  Add-2+3usingtwo’scomplementnumbers

Two’sComplementAddition

+01101010

+11100011

38

Page 39: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Add6+(-6)usingtwo’scomplementnumbers

•  Add-2+3usingtwo’scomplementnumbers

Two’sComplementAddition

+0110101010000

111

+1110001110001

111

39

Page 40: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

IncreasingBitWidth

ExtendnumberfromNtoMbits(M>N):–  Sign-extension–  Zero-extension

40

Page 41: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Signbitcopiedtomsb’s•  Numbervalueissame

•  Example1:–  4-bitrepresentationof3=0011–  8-bitsign-extendedvalue:00000011

•  Example2:–  4-bitrepresentationof-5=1011–  8-bitsign-extendedvalue:11111011

Sign-Extension

41

Page 42: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

•  Zeroscopiedtomsb’s•  Valuechangesfornegativenumbers

•  Example1:–  4-bitvalue=0011=310–  8-bitzero-extendedvalue:00000011=310

•  Example2:–  4-bitvalue=1011=-510–  8-bitzero-extendedvalue:00001011=1110

Zero-Extension

42

Page 43: Logic Design...Digital Systems • Digital discipline –Discrete voltages instead of continuous –Simpler to design than analog circuits • can build more sophisticated systems

NumberSystemComparison

NumberSystem RangeUnsigned [0,2N-1]

Sign/Magnitude [-(2N-1-1),2N-1-1]

Two’sComplement [-2N-1,2N-1-1]

Forexample,4-bitrepresentation:

-8

1000 1001

-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Two's Complement

10001001101010111100110111101111

00000001 0010 0011 0100 0101 0110 0111

1000 1001 1010 1011 1100 1101 1110 11110000 0001 0010 0011 0100 0101 0110 0111

Sign/Magnitude

Unsigned

43