ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with...

40
ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE

Transcript of ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with...

Page 1: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

ECE 171Digital Circuits

Chapter 1Numbers

Herbert G. Mayer, PSUStatus 12/10/2015

Copied with Permission from prof. Mark Faust @ PSU ECE

Page 2: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Syllabus

Introduction Why Study Digital Systems The Old Days Now Features Digital vs. Analog Systems Decimal Fractions Binary Octal

Page 3: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Introduction• Professor Mark G. Faust created material

– 12th year at PSU• Teach digital design, computer architecture, product design• Supervise Senior Capstone Program

– > 20 years experience in industry• 3 startups (one failure, one IPO, one acquisition)• 2 large public companies• Extensive consulting• Product design and development

– Engineer, Manager, Vice-President Engineering– Technical Product Marketing Manager

• Sales/service/technical support of complex technical products– General Manager, Asian Operations

• Lived and worked extensively in Europe and Asia

3

Page 4: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Introduction

• Dr. Herbert G. Mayer– 27th year at PSU

• Teach digital design, computer architecture• Mostly in CS Department• Since 2 years at ECE

– > 30 years experience in industry• Mostly Compiler Construction• And managing technical design teams at Intel• For chipset design (of Merced, early name for Itanium)

For performance validation• And for function validation of new silicon

4

Page 5: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Why Study Digital Systems

• Because you’ll probably– Design them as EEs later in life– Use them– Interface with them– Program them

• They are ubiquitous– Obvious: PCs, Consumer Electronics

• Audio, Video, Cameras, Phones, Cable Set-top Boxes, Games– Also: Appliances, Automobiles, Medical Devices

5

Page 6: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

The old days…• Only electronics – car radio (analog)

6

Page 7: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Now…• Hybrid vehicle

– >150 motors, solenoids to control– >15 microcontrollers (MCUs)– >100 sensors to be checked– Airbags and belt pretensioners to be fired/pre-fired– 60kW of electrical power to control

7

Page 8: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Features

• Digital satellite radio • GPS guidance systems• ABS brakes• Fuel injection• Anti-collision systems • Video camera• Cell phone• Entertainment systems (DVD, CD, MP3)• Anti-theft system

8

Page 9: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Digital Systems

• Two Valued (Binary) System– On/Off– High/Low Voltage– Open/Closed Switch (vs. “Dimmer” Switch)– Magnetized/Unmagnetized– 1/0

9

Page 10: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Digital vs. Analog Systems

• Analog systems– continuous change

• Digital systems– discrete change

10

Page 11: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Digital vs. Analog

Continuous

Discrete

(Analog audio)

(Digital audio: CD, MP3)

11

Page 12: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Lecture 1

• Topics– Radix number representations

• Decimal, Binary, Octal, Hexadecimal• Conversions

– Decimal to Binary, Octal, Hexadecimal– Binary, Octal, Hexadecimal to Decimal– Group of 3 for Octal– Group of 4 for Hexadecimal

12

Page 13: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Decimal

623410

1000 100 10 1 103 102 101 100

6 2 3 4

dndn-1…d1d0 = dn x 10n + dn-1 x 10n-1 + … d1 x 101 + d0 x 100

where: 0 £ d £ 9

623410 = 6 x 103 + 2 x 102 + 3 x 101 + 4 x 100

MSD

LSD

Radix or Base 10 (Why?)

Zero referencing13

Page 14: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Decimal

• Question: How many unique (non-negative) n digit decimal numbers are there?– 10n

– 1 digit: 0-9, 10 (101)– 2 digits: 00-99, 100 (102)– 3 digits: 000-999, 1000 (103)

• Question: What’s the largest n digit decimal number?– 10n-1

14

Page 15: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Binary

11012

8 4 2 1 23 22 21 20

1 1 0 1

dndn-1…d1d0 = dn x 2n + dn-1 x 2n-1 + … d1 x 21 + d0 x 20

where: 0 £ d £ 1

11012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20

MSB

LSB

Zero referencing

Radix or Base 2 (Why?)

bit(binary digit)

word size

15

Page 16: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Binary

1101101110010001MSB

LSB

4 bit “nibble” 8 bit “byte”

This example: 16 bit word

16

Note: a Byte –i.e. an 8-bit unit– is only a byte, if it is also uniquely addressable!!

Page 17: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Binary• Question: How many different (non-negative) n bit

binary numbers are there?– 2n

– 1 bit: {0,1} 2 (21)– 2 bits: {00, 01, 10, 11}, 4 (22)– 3 bits: {000, 001, 010, 011, 100, 101, 110, 111}, 8 (23)

• Question: What’s the largest n bit binary number (what’s the largest number you can represent in an n bit word)?– 2n-1

17

Page 18: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Binary• Question: How many bits (what word size) do you

need to represent a number n in binary?– Let’s first ask: How many bits do you need to represent

n different binary numbers?• élog2 nù • 1 bit: n = (21) numbers• 2 bits: n = (22) numbers• 3 bits: n = (23) numbers• m bits: n = 2m numbers• Ceiling function because we need an integer number of bits

– Now, to represent number n, how many different numbers? n+1, so

– élog2 (n+1)ù18

Page 19: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Decimal Fractions

6234.12510

1000 100 10 1 1/10 1/100 1/1000 103 102 101 100 10-1 10-2 10-3

6 2 3 4 . 1 2 5

dndn-1…d1d0 .d-1…d-m = dn x 10n + dn-1 x 10n-1 + … d1 x 101

+ d0 x 100 + d-1 x 10-1 + … d-m x 10-m

where: 0 £ d £ 9

6234.12510 = 6 x 103 + 2 x 102 + 3 x 101 + 4 x 100

+ 1 x 10-1 + 2 x 10-2 + 5 x 10-3

19

Page 20: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Binary Fractions (“Fixed Point”)

1101.1012

8 4 2 1 1/2 1/4 1/8 23 22 21 20 2-1 2-2 2-3

1 1 0 1 . 1 0 1

dndn-1…d1d0 .d-1…d-m = dn x 2n + dn-1 x 2n-1 + … d1 x 21 + d0 x 20

+ d-1 x 2-1 + … d-m x 2-m

where: 0 £ d £ 1

1101.1012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20

+ 1 x 2-1 + 0 x 2-2 + 1 x 2-3

20

Page 21: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Octal

27368

512 64 8 1 83 82 81 80

2 7 3 6

dndn-1…d1d0 = dn x 8n + dn-1 x 8n-1 + … d1 x 81 + d0 x 80

where: 0 £ d £ 7

27368 = 2 x 83 + 7 x 82 + 3 x 81 + 6 x 80

Radix or Base 8 (Why?)

21

Page 22: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

OctalRadix or Base 8 (Why?)Groups of 3 bits (8 = 23)

27368 = 010 111 011 1102

2 7 3 6

27368 = 010 111 011 1102

4 2 1 4 2 1 4 2 1 4 2 1

22

Page 23: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Converting from Binary to Octal

• Example: Convert 10111.11 to Octal

10111.11

… 010111.110 …

2 7 6

27.68

Group by 3sExtend leading, trailing 0s if neededConvert each grouping to octal

4 2 1 4 2 1 4 2 1

23

Page 24: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Hexadecimal

273616

4096 256 16 1 163 162 161 160

2 7 3 6

dndn-1…d1d0 = dn x 16n + dn-1 x 16n-1 + … d1 x 161 + do x 160

where: 0 £ d £ 15 !!

273616 = 2 x 163 + 7 x 162 + 3 x 161 + 6 x 160

Radix or Base 16 (Why?)10 = A11 = B12 = C13 = D14 = E15 = F

24

Page 25: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Hexadecimal

2A3F16

4096 256 16 1 163 162 161 160

2 A 3 F

2A3F16 = 2 x 163 + A x 162 + 3 x 161 + F x 160

10 = A11 = B12 = C13 = D14 = E15 = F

2A3F16 = 2 x 163 + (10) x 162 + 3 x 161 + (15) x 160

2A3F16 = 1081510

25

Page 26: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

HexadecimalRadix or Base 16 (Why?)Groups of 4 bits (16 = 24)

2 A 3 F

2A3F16 = 0010 1010 0011 11112

10 = A11 = B12 = C13 = D14 = E15 = F

2A3F16 = 0010 1010 0011 11112

8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1

26

Page 27: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Converting from Binary to Hex

• Example: Convert 10111.11 to Hex

10111.11

… 00010111.1100 …

17.C16

Group by 4sExtend leading, trailing 0s if neededConvert each grouping to hex1 7 C

8 4 2 1 8 4 2 18 4 2 1

27

Page 28: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Decimal Conversions

• Conversions from Decimal– “Subtract the Weights” Method– Repeated Radix Division (RRD)/Multiplication (RRM)

Method• Conversions to Decimal

– Polynomial Function Method

28

Page 29: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Subtract the Weights

• Example: Convert 7610 to binary28 = 25627 = 12826 = 6425 = 3224 = 1623 = 822 = 421 = 220 = 1

76- 64 12

12 - 8 4

4 - 4 0

1001100

7610 = 10011002 Works for other bases, too

MSB

LSB

Generates MSB first

29

Page 30: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Repeated Radix Division (RRD)• Example: Convert 7610 to binary

7610 = 10011002 Works for other bases, too

2 | 76 0 | 38 0 | 19 1 | 9 1 | 4 0 | 2 0 | 1 1

Remainder

MSB

LSB

Generates LSB first

30

Page 31: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Repeated Radix Multiplication (RRM)

• Example: Convert 0.12510 to binary

0.125x 20.250

0.250x 20.500

0.500x 21.000

Continue multiplying fractional part until 0Record whole bits generated

0.0012Works for other bases, too

MSB LSBGenerates MSB first

31

Page 32: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Polynomial Function Method

• Example: Convert 4B.C216 to decimal

4B.C216 = 4 x 161 + B x 160 + C x 16-1 + 2 x 16-2

= 4 x 16 + (11) x 1 + 12 x 1/16 + 2 x 1/162

= 4 x 16 + (11) x 1 + 12 x 1/16 + 2 x 1/162

= 64 + 11 + 12 x 0.0625 + 2 x 0.00390625= 75 + 0.75 + 0.0078125= 75.7578125

32

Page 33: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Conversion Summary• From Decimal

– RRD Method for Integers (generates LSB first)– RRM Method for Fractions (generates MSB first)

• To Decimal– Polynomial Function Method

• Between Binary and Hex/Octal– Use Groups of 4 (Hex) or 3 (Octal)

• Remember to extend leading/trailing 0s where necessary!• For Conversions Between Decimal/Binary

– Consider Using Hex or Octal to Reduce Work– Then Convert Between Binary and Hex/Octal

33

Page 34: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Data in Memory

To load and store data, the CPU needs data in memory

If they are not, data are read from secondary storage into memory

Many computers organize they memory in units of bytes, these are 8-Bit units, each of which is addressable

Larger data are often processed in units of integers, floating point, and extended-precision versions of those

The processor has specific operations for any operation, i.e. float ops, integer ops, byte ops, and more

Bytes are arranged in a word sequentially, in big endian or little endian order -- we do not cover in ECE 101

Page 35: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Data in Memory

On a 32-bit, byte-addressable architecture it is convenient to view memory as a linear sequence of bytes, the first at address 0, the last at 232-1

On such a machine, words are contiguous groups of 4 bytes, whose first address is evenly divisible by 4

This is referred to as an aligned address Similarly on 64-bit word machines; there the first byte

address is evenly divisible by 8; else it is unaligned Most computers still can load/store words at any

address, but unaligned accesses cause multiple bus transactions, and thus slow down execution

Page 36: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Data in Memory

C Data Type Size [bits]

Min Value Max Value

char, signed char 8 -128 127

unsigned char 8 0 255

short int, signed short int 16 -32768 +32767

unsigned short int 16 0 65535

int, signed int 32 -2147483648 +2147483647

unsigned int 32 0 4294967295

float 32 approx -1038 approx 1038

double 64 approx -10308 approx 10308

Page 37: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Data in Memory: ASCII CharactersDec Hex Char Dec Hex Char Dec Hex Char Dec Hex Char

0 00 Null 32 20 Space 64 40 @ 96 60 ‘

1 01 Start of heading 33 21 ! 65 41 A 97 61 a

2 02 Start of text 34 22 " 66 42 B 98 62 b

3 03 End of text 35 23 # 67 43 C 99 63 c

4 04 End of transmit 36 24 $ 68 44 D 100 64 d

5 05 Enquiry 37 25 % 69 45 E 101 65 e

6 06 Acknowledge 38 26 & 70 46 F 102 66 f

7 07 Audible bell 39 27 ' 71 47 G 103 67 g

8 08 Backspace 40 28 ( 72 48 H 104 68 h

9 09 Horizontal tab 41 29 ) 73 49 I 105 69 i

10 0A Line feed 42 2A * 74 4A J 106 6A j

11 0B Vertical tab 43 2B + 75 4B K 107 6B k

12 0C Form feed 44 2C , 76 4C L 108 6C l

13 0D Carriage return 45 2D - 77 4D M 109 6D m

14 0E Shift out 46 2E . 78 4E N 110 6E n

15 0F Shift in 47 2F / 79 4F O 111 6F o

16 10 Data link escape 48 30 0 80 50 P 112 70 p

17 11 Device control 1 49 31 1 81 51 Q 113 71 q

18 12 Device control 2 50 32 2 82 52 R 114 72 r

19 13 Device control 3 51 33 3 83 53 S 115 73 s

20 14 Device control 4 52 34 4 84 54 T 116 74 t

21 15 Neg. acknowledge 53 35 5 85 55 U 117 75 u

22 16 Synchronous idle 54 36 6 86 56 V 118 76 v

23 17 End trans. block 55 37 7 87 57 W 119 77 w

24 18 Cancel 56 38 8 88 58 X 120 78 x

25 19 End of medium 57 39 9 89 59 Y 121 79 y

26 1A Substitution 58 3A : 90 5A Z 122 7A z

27 1B Escape 59 3B ; 91 5B [ 123 7B {

28 1C File separator 60 3C < 92 5C \ 124 7C |

29 1D Group separator 61 3D = 93 5D ] 125 7D }

30 1E Record separator 62 3E > 94 5E ^ 126 7E ~

31 1F Unit separator 63 3F ? 95 5F _ 127 7F □

Page 38: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

Number of Numbers with n Bits

n # States n # States n # States

0 none 10 1,024 20 1,048,576

1 2 11 2,048 21 2,097,152

2 4 12 4,096 22 4,194,304

3 8 13 8,192 23 8,388,608

4 16 14 16,384 24 16,777,216

5 32 15 32,768 : :

6 64 16 65,536 30 1,073,741,824

7 128 17 13,1072 31 2,147,483,648

8 256 18 26,2144 32 4,294,967,296

9 512 19 52,4288 64 18446744073709551616

Page 39: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

39

A B A & B

0 0 0

0 1 0

1 0 0

1 1 1

A B A | B

0 0 0

0 1 1

1 0 1

1 1 1

A B A ^ B

0 0 0

0 1 1

1 0 1

1 1 0

A ~A

0 1

1 0

Bitwise AND

Bitwise OR

Bitwise XOR

Bitwise Compleme

nt A B A + B Carry

0 0 0 0

0 1 1 0

1 0 1 0

1 1 0 1

Bitwise Addition

Some Bitwise Operations

Page 40: ECE 171 Digital Circuits Chapter 1 Numbers Herbert G. Mayer, PSU Status 12/10/2015 Copied with Permission from prof. Mark Faust @ PSU ECE.

References

1. Digital Design, Principles and Practices, © John F. Wakerly, Pearson Prentice Hall, 4th edition

2. Electric Circuits, James W. Nielsson and Susan A. Riedel, Pearson Education Inc., publishing as as Prentice Hall, © 2015, ISBN-13: 978-0-13-376003-3