12
Principles Of Digital Design Numbers Number Representations Decimal, Binary Number System Complement Number System Fixed Point and Floating Point Numbers

Principles Of Digital Design - CECS

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Principles Of Digital Design - CECS

Principles Of Digital Design

Numbers

Number Representations Decimal, Binary Number System Complement Number System Fixed Point and Floating Point Numbers

Page 2: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 2

Each number is represented by a string of digits, in which the position of each digit has an associated weight 1234.56 = 1 ∙ 1000 + 2 ∙ 100 + 3 ∙ 10 + 4 ∙ 1 + 5 ∙ 0.1 + 6 ∙ 0.01

In general, any decimal number D of the form

has the value

Positional Number System

dm – 1 dm – 2 …d1 d0 .d–1 d–2 …d–n

Least significant digit Radix point Most significant digit

Radix

D = dm – 1 ∙ 10m – 1 + …+ d0 ∙ 100 + d–1 ∙ 10–1 + …+ d–n ∙ 10–n = ∑ −

− =

⋅ 1

10 m

n i

i i d

Page 3: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 3

General form of a binary number:

Its value is equivalent to

Examples

Binary Number System

bm – 1 bm – 2 …b1 b0 .b–1 b–2 … b–n

Least significant bit (LSB) Binary point Most significant bit (MSB)

B =

Radix 2

101012 = 1 ∙ 16 + 0 ∙ 8 + 1 ∙ 4 + 0 ∙ 2 + 1 ∙ 1 = 2110

1101012 = 1 ∙ 32 + 1 ∙ 16 + 0 ∙ 8 + 1 ∙ 4 + 0 ∙ 2 + 1 ∙ 1 = 5310

10.1012 = 1 ∙ 2 + 0 ∙ 1 + 1 ∙ 0.5 + 0 ∙ 0.25 + 1 ∙ 0.125 = 2.62510

0.11112 = 1 ∙ 0.5 + 1 ∙ 0.25 + 1 ∙ 0.125 + 1 ∙ 0.0625 = 0.937510

∑ −

− =

⋅ 1

2 m

n i

i i b

Page 4: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 4

Dividing the top equation by 2, we obtain the quotient S and remainder R

Conversion from Decimal to Binary

S = (…((bn – 1)2 + bn – 2)2 + …)2 + b1 R = b0

Divide S by 2 S = quotient bi = remainder

i = 0

S = D

Start

S = 0?

i = i + 1

Done

no

yes

Continuing dividing S by 2, we obtain the new quotient S and next binary digit

B = = ((…((bn – 1)2 + bn – 2)2 + …)2 + b1)2 + b0 ∑ −

0 =

⋅ 1

2 n

i

i i b

D = = ((…((dm – 1)10 + dm – 2)10 + …)10 + d1)10 + d0 ∑ −

0 =

⋅ 1

10 m

i

i i d

Page 5: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 5

Decimal-to-Binary Example Problem: Convert 179 to binary, Solution: B = 10110011

1 7 9 ÷ 2 = 8 9 remainder 1 (b0) 8 9 ÷ 2 = 4 4 remainder 1 (b1) 4 4 ÷ 2 = 2 2 remainder 0 (b2) 2 2 ÷ 2 = 1 1 remainder 0 (b3) 1 1 ÷ 2 = 5 remainder 1 (b4)

5 ÷ 2 = 2 remainder 1 (b5) 2 ÷ 2 = 1 remainder 0 (b6) 1 ÷ 2 = 0 remainder 1 (b7)

Therefore, 17910 = b7b6 b5 b4 b3 b2 b1 b0 = 101100112

Divide S by 2 S = quotient bi = remainder

i = 0

S = D

Start

S = 0?

i = i + 1

Done

no

yes

Page 6: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 6

Conversion from Binary to Decimal

D = D x 2 + bi

i = n – 1

D = 0

Start

i = 0

i = i – 1

Done

no

yes

Problem: Convert 10110011 to decimal, Solution: D = 179,

0 x 2 + 1 = 1

1 x 2 + 0 = 2

2 x 2 + 1 = 5

5 x 2 + 1 = 11

11 x 2 + 0 = 22

22 x 2 + 0 = 44

44 x 2 + 1 = 89

89 x 2 + 1 = 179

Therefore, b7 b6 b5 b4 b3 b2 b1 b0 = 10110011 => 179

B = = ((…((bn – 1)2 + bn – 2)2 + …)2 + b1)2 + b0 ∑ −

0 = ⋅

1

2 n

i

i i b

b i D

Page 7: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 7

Sign Magnitude Representation

A sign magnitude number <s, m>, consists of two parts: Sign (s) and Magnitude (m) The sign is either + or – The magnitude is an integer between 0 and the largest representable value

Examples:

011110112 = +12310 111110112 = –12310

Page 8: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 8

Two’s-complement of a number B = (ex. 0110) is equal to: (1111- 0110 + 1)

Proof: If digit complement b′ = (2 – 1) – b = 1 - b then

Therefore, (1010 = 1001 + 1 ) where is a negative number of , since (1010 + 0110 = 10000)

Two’s Complement Number System

(2m – 1) – B = ( (2 – 1) (2 – 1) … (2 – 1) – (bm – 1 bm – 2 … b0 ) )

= ( (2 – 1) – bm – 1) ( (2 – 1) – bm – 2 ) … ( (2 – 1) – b0 ) = b′m – 1 b′m – 2 … b′0 = = B′ (1001)

∑ −

0 =

⋅ 1

2 m

i

i i b

B 1 ) ) 1 2 (( 2 + − − = − = B B m m

∑ −

=

1

0 '

m

i i b

1 ' + = B B

B 0 = + B B B

Page 9: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 9

Complement Number System

Decimal Two’s Complement

Sign- Magnitude

-8 1000 -

-7 1001 1111

-6 1010 1110

-5 1011 1101

-4 1100 1100

-3 1101 1011

-2 1110 1010

-1 1111 1001

0 0000 1000 or 0000

1 0001 0001

2 0010 0010

3 0011 0011

4 0100 0100

5 0101 0101

6 0110 0110

7 0111 0111

Two’s Complement and Sign-Magnitude Representations

Page 10: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 10

Floating-point numbers have the form mantissa × (radix) exponent

Since radix is implicit, only mantissa and exponent must be represented explicitly

Floating-point numbers are fixed-point numbers given by the mantissa, whose radix point is specified by the exponent

Exponent is represented in the excess-code format called characteristic, obtained by adding a bias to the exponent:

bias = (radixs /2 ) – 1

where s is equal to the number of bits in the exponent field

Floating-point Numbers

Mantissa sign

Signed exponent

Mantissa magnitude

Sign Excess-127 characteristic

Normalized Fraction Sign Excess-1023

characteristic Normalized

Fraction

32-bit standard

0 1 9 31 0 1 12 63

Implied binary point Implied binary point 64-bit standard

General format

Page 11: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine 11

Fixed-point vs. Floating-point

4-digit fixed number 4-digit floating-point number

Integer

Mantissa

Exponent

Representable numbers 0 – 9999 0 – 99 × 10 0-99

Range ~ 104 ~ 10101

Precision ~ 100× ~ 1×

Example 1001 numbers

between 1000 and 2000 1000, 1001,…1999,2000

11 numbers between 1000 and 2000

10x102, 11x102,… 19x102,20x102

The range is the interval of numbers from the largest to the smallest representable number

The precision is the amount of numbers in a number interval

Page 12: Principles Of Digital Design - CECS

Copyright © 2010-2012 by Daniel D. Gajski ! EECS31/CSE31, University of California, Irvine

Summary

Digits and Numbers Decimal Binary

Number Representation Sign- magnitude Twos-Complement Floating-point