ECE456: Number Systems (review) Instructor: Dr. Honggang Wang II-209B, hwang1@umassd.edu ECE Dept.,...

Post on 13-Jan-2016

218 views 0 download

Transcript of ECE456: Number Systems (review) Instructor: Dr. Honggang Wang II-209B, hwang1@umassd.edu ECE Dept.,...

ECE456: Number Systems (review)

Instructor: Dr. Honggang Wang

II-209B, hwang1@umassd.edu

ECE Dept., Fall 2013

Dr. Wang

Administrative Issues (9/16/13)

• Project team set-up due Wednesday, Sept. 25

• If you missed the first class, go to the course website for syllabus and 1st lecture.

http://www.faculty.umassd.edu/honggang.wang/teaching.html

Dr. Wang

1 Mega bytes = 2? bytes

a) 26 bytes (x)

b) 217 bytes (x)

c) 1024 bytes (x)

d) 216 bytes (x)

e) 1E7 bytes (x)

f) 210 bytes (x)

g) 232 bytes (x)

h) No answer (x)

From Background Survey

Number Systems

• Do you know the equivalent hexadecimal, octal, and decimal values of the binary number 11001010?

• What is the equivalent binary number of the decimal number 63?

Dr. Wang

From Background Survey

Dr. Wang

ConventionsTerm Normal Usage Usage as a Power of 2

Kilo (K) 103 210 =1,024

Mega (M) 106 220 =1,048,576

Giga (G) 109 230 =1,073,741,824

Tera (T) 1012 240 =1,099,511,627,776

Mili (m) 10-3

Micro (m) 10-6

Nano (n) 10-9

Pico (p ) 10-12

• Powers of 2 are most often used in describing memory capacity.– Ex: 1Kilobyte (KB) =1024 bytes= 210 bytes

• Powers of 10 are used to describe the CPU clock frequencies: cycles per second (Hz)– Ex: Pentium 4 --1.8GHz = 1.8x109 Hz

Dr. Wang

DefinitionsTerm Definition

bit 0 or 1

byte (B) a group of 8 bits

nibble (nybble) half a byte (4 bits)

word (w) a group of bits that is processed simultaneously.

a word may consist of 8/16/32/other number of bits

machine dependent

(ex: 8086 – 16 bits; 80386/80486/Pentium – 32 bits)

double word 2 words

msb (most significant bit) the leftmost bit in a word

lsb (least significant bit) the rightmost bit in a word

Hz (hertz) reciprocal of second

Dr. Wang

Review of Number Systems

• Overview

• Number systems conversions

Chapter 19 (online chapter)Or Appendix A in 7th edition

Dr. Wang

Number SystemsNumber Systems

• Two basic types of number systems:

– Non-positional• Ex: Roman numerals: I, II, III, IV, V … X, XI … C

• Normally only useful for small numbers

– Positional• Ex: the decimal systems

• Each position in which a digit/symbol is written has a different

positional value, which is a power of the base

Dr. Wang

Decimal number systems 1. a base of 10 (determines the magnitude of a place).

2. is restricted to 10 re-usable digits/symbols (0,1,2,3,4,5,6,7,8,9)

3. the value of a digit depends on its position

(digit x positional value = digit x baseposition)

4. sum of the value of all digits gives the value of the number.

Positional Number Systems (Example)

58710 = 5 x 102 + 8 x 101 + 7 x 100

= 5 x 100 + 8 x 10 + 7 x 1

= 500 + 80 + 7

= 587

Dr. Wang

Positional Number Systems

In general (base is b),

N = ...P3P2P1P0 . P-1P-2P-3...

= ... + P3b3 + P2b2 + P1b1 + P0b0 + P-1b-1 + P-2b-2 + P-3b-3 + ...

Decimal (base is 10):

375.1710 = 3 x 102 + 7 x 101 + 5 x 100 + 1 x 10-1 + 7 x 10-2

= 3 x 100 + 7 x 10 + 5 x 1 + 1 x 0.1 + 7 x 0.01

= 300 + 70 + 5 + 0.1 + 0.07

= 375.17

0Increase by 1 Decrease by 1

Dr. Wang

• Specify the value of the digit 5 in the following decimal

numbers:

Exercise (1)

25

51

4538

Dr. Wang

• Binary– Base 2– 2 symbols:0,1

• Octal– Base 8– 8 symbols: 0,1,2,3,4,5,6,7

– ,3,4,5,6,7,8,9

• Hexadecimal– Base 16– 16 symbols: 0,1,2,3,4,5,6,7,8,9,

A,B,C,D,E,F– More compact representation

of the binary system

• Decimal– Base 10– 10 symbols: 0,1,2,3,4,5,6,7,8,9

Decimal

(base 10)

Binary

(base 2)

0 0

1 1

2 10

3 11

4 100

5 101

6 110

7 111

8 1000

9 1001

10 1010

11 1011

12 1100

13 1101

14 1110

15 1111

16 10000

17 10001

Octal

(base 8)

Hexadecimal

(base 16)

0 0

1 1

2 2

3 3

4 4

5 5

6 6

7 7

10 8

11 9

12 A

13 B

14 C

15 D

16 E

17 F

20 10

21 11

Dr. Wang

Example of Equivalent Numbers

Binary: 1 0 1 0 0 0 0 1 0 1 0 0 1 1 12

Octal: 502478

Decimal: 2064710

Hexadecimal: 50A716

Notice how the number of digits gets

smaller as the base increases.

Dr. Wang

Agenda

• Overview of number systems

– Positional and non-positional

– Base, positional value, symbol value

– Binary, decimal, octal, hexadecimal

• Number systems conversions

Dr. Wang

Number Systems Conversions

• Binary, Octal, and Hex to Decimal• Decimal to Hex, Octal, and Binary• Binary Hex• Binary Octal• Hex Octal

Dr. Wang

1. Binary, Octal, Hex Decimal

In general (base is b: 2 for binary, 8 for Octal, 16 for Hex),

N = ...P3P2P1P0 . P-1P-2P-3...

= ... + P3b3 + P2b2 + P1b1 + P0b0 + P-1b-1 + P-2b-2 + P-3b-3 + ...

Multiply the decimal equivalent of each digit by its positional/place value (a power of the base) and sum these products

Dr. Wang

Exercise (2)

• Convert the following numbers to their decimal equivalents

10011012

1101.112

1AB.616

173.258

Dr. Wang

2. Decimal Binary, Octal, or Hex

To convert decimal numbers to any base we divide with the corresponding base until the quotient is zero and write the remainders in reverse order.

Dr. Wang

Decimal Octal, Binary, Hex

• Divide the decimal number successively by 8 (for Octal), 2 (for Binary), 16 (for Hex)

• After each division record the remainder– Octal: 0,1,…, or, 7

– Binary: either a 1 or 0

– Hex: 1, 2,…, or,9, or A, B, …, or F

• Continue until the result of the division (quotient) is 0

• Write the remainders in reverse order

Dr. Wang

Exercise (3)

• Convert 123|10 to Base 8

• Convert 59|10 to Base 2

• Convert 42|10 to Base 16

Dr. Wang

Number Systems Conversions(Agenda)

Binary, Octal, and Hex to DecimalDecimal to Hex, Octal, and Binary• Binary Hex• Binary Octal• Hex Octal

Dr. Wang

Binary Hex

Dr. Wang

Binary to Hexadecimal Conversion

10100010111001|2 = ?|16

Work from right to left

Divide into 4-bit groups

##10 1000 1011 1001

2 8 B 9

Decimal Binary Hexadecimal

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

8 1000 8

9 1001 9

10 1010 A

11 1011 B

12 1100 C

13 1101 D

14 1110 E

15 1111 F

NOTE: # is a place holder for zero!

Dr. Wang

Hexadecimal to Binary Conversion

FACE|16 = ?|2

F A C E

1111 1010 1100 1110

Decimal Binary Hexadecimal

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

8 1000 8

9 1001 9

10 1010 A

11 1011 B

12 1100 C

13 1101 D

14 1110 E

15 1111 F

FACE|16=1111101011001110|2

Dr. Wang

Binary Octal

Dr. Wang

10101110001101|2=?|8

#10 101 110 001 101

2 5 6 1 5

10101110001101|2=25615|8

Binary to Octal Conversion

Binary Octal

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

Work from right to left Divide into 3 bit groups

Dr. Wang

1247|8=?|2

1 2 4 7

001 010 100 111

Octal to Binary Conversion

Note: one need not write the leading zeros

1247|8=001010100111 |2

=1010100111|2

Binary Octal

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

Dr. Wang

Hexadecimal Octal

Dr. Wang

How do we convert fromhexadecimal to octal and

vice versa?

Convert to binary first!

Dr. Wang

Exercise (4)

• Do you know the equivalent hexadecimal, octal, and decimal values of the binary number 11001010? ______Yes _______No If you answered Yes, please indicate them below:

– Equivalent hexadecimal number:________________– Equivalent octal number: __________________– Equivalent decimal number: __________________

• What is the equivalent binary number of the decimal number 63? _____________________________

From Background Survey

Dr. Wang

Exercise (5)

• Convert 18110 to binary and hex

• Convert 121F16 to decimal

• Convert 010101011002 to hex

• Convert A17F16 to octal

Dr. Wang

Summary

1. Basic number systems concepts (base, positional/place value, symbol value)

2. Convert back and forth between decimal numbers and their binary, octal, and hexadecimal equivalents

3. Abbreviate binary numbers as octal or hexadecimal numbers

4. Convert octal and hexadecimal numbers to binary numbers

Dr. Wang

• Specify the value of the digit 5 in the following decimal

numbers:

Solution (1)

the 5 in 25 = 5 x 100 = 5

the 5 in 51 = 5 x 101 = 50

the 5 in 4538 = 5 x 102 = 500

Dr. Wang

Solution (2)

10011012 = 1 x 26 + 0 x 25 + 0 x 24 + 1 x 23 + 1 x 22 + 0 x 21+1 x 20 = 64 + 0 + 0 + 8 + 4 + 0 + 1 = 7710

1101.112 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 + 1 x 2-1 + 1 x 2-2 = 8 + 4 + 0 + 1 + 1/2 + 1/4 = 13.7510

1AB.616 = 1 x 162 + A x 161 + B x 160 + 6 x 16-1 = 1 x 256 + 10 x 16 + 11 x 1 + 6 x 16 = 256 + 160 + 11 + 0.375 = 427.37510

173.258 = 1 x 82 + 7 x 81 + 3 x 80 + 2 x 8-1 + 5 x 8-2

= 1 x 64 + 7 x 8 + 3 x 1 + 2/8 + 5/64 = 64 + 56 + 3 + 0.25 + 0.078125 = 123.32812510

Dr. Wang

Convert 123|10 to Base 8:

8 )123

8 )15 R 3

8 )1 R 7

0 R 1

Therefore, 123|10 = 173|8

Solution (3-1)

Base you are converting to

Read Up!

Dr. Wang

Solution (3-2)

• Convert 59|10 to Base 2:

59|10 =1110112

• Convert 42|10 to Base 16:

16 )42

16 )2 R A

0 R 2Read Up!

Therefore, 42|10 = 2A|16

Dr. Wang

Solution (4)

• Do you know the equivalent hexadecimal, octal, and decimal values of the binary number 11001010? ______Yes _______No If you answered Yes, please indicate them below:

– Equivalent hexadecimal number:__CA___________– Equivalent octal number: _______312___________– Equivalent decimal number: _____202_____________

• What is the equivalent binary number of the decimal number 63? ________111111_____________

From Background Survey

Dr. Wang

Solution (5)

• Convert 18110 to binary (10110101) and hex (B5)

• Convert 121F16 to decimal (4639 10 )

• Convert 010101011002 to hex (2AC16)

• Convert A17F16 to octal (1205778)