Docsity

Computer Arithmetic: Algorithms and Hardware Design - Lecture Slides | ECE 645, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Computer Arithmetic: Algorithms and Hardware Design - Lecture Slides | ECE 645 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Number Representation

ECE 645: Lecture 1

Required Reading

Chapter 1, Numbers and Arithmetic, Sections 1.1-1.6, pp. 3-

Chapter 2, Representing Signed Numbers, Sections 2.1-2.6, pp. 19-

Behrooz Parhami, Computer Arithmetic: Algorithms and Hardware Design

Codes for Numbers

  • Egyptian
    • ~4000 BC
    • “Sum of Symbols” =1 =10 =

= (34) 10

Positional Code for Numbers

  • Babylonians
    • Positional system
    • 2000 BC
    • Radix 60
    • = 1 = 10

Mixed System

  • Roman Numerals
    • Sum of all symbols
    • I=1 V=5 X=10 L=50 C=100 D=500 M=
    • Difficult to do arithmetic
    • e.g. ,

?

IX

MCDXLVII −

Hindu-Arabic Numeral System

Brahmi numerals, India, 400 BC-400 AD

Evolution of numerals in early Europe

Positional Code Decimal

System

  • Documented in the 9th century
  • Position of coefficient determines its value
  • Coefficient in position is multiplied by radix (10) raised to the power determined by its position, e.g.,

Migration of Positional

Notation

  • ~750 AD
    • Zero spread from India to Arabic countries
  • ~1250 AD
    • Zero spread to Europe
  • Importance of Zero
    • Ease of arithmetic which leads to improved commerce

Classification of number systems (2)

Positional

wi - weight of the digit xi

Fixed-radix

i

k

i l

X = (^) ∑ xi ⋅ w

−

=−

1

i

k

i l

X = (^) ∑ xi ⋅ r

−

=−

1 r - radix of the number system

Conventional fixed-radix

i

k

i l

X = (^) ∑ xi ⋅ r

−

=−

1 r integer, r > 0 x i ∈ {0, 1, …, r -1}

Classification of number systems (3)

Unconventional fixed-radix

i

k

i l

X = (^) ∑ xi ⋅ r

−

=−

1 x i ∈ {-α, …, β }

Non-redundant number of digits = α + β + 1 ≤ r Redundant number of digits = α + β + 1 > r

Signed-digit α>0 ^ negative digits

Integral and fractional part
X = xk -1 xk -2 … x 1 x 0. x -1 x -2 … x - l

Integral part Fractional part

Radix point

  • NOT stored in the register
  • understood to be in a fixed position

Fixed-point representation

Range of numbers

Decimal

X = ( xk -1 xk -2 … x 1 x 0. x -1 … x - l ) 10

X min X max

0 10 k^ - 10- l

Binary

Number system

X = ( xk -1 xk -2 … x 1 x 0. x -1 … x - l ) 2 0 2 k^ - 2- l

Conventional fixed-radix

X = ( xk -1 xk -2 … x 1 x 0. x -1 … x - l ) r 0 rk^ - r - l

ulp = r - l

Notation: (^) u nit in the l east significant p osition u nit in the l ast p osition

Radix Conversion of the Fractional Part

XF = (. x -1 x -2 … x - l +1 x - l )R = =

R - destination radix

i i l

∑ xi^ ⋅ R

−

=−

1

= R-1^ ( x-1 + R-1^ ( x-2 + R-1^ (…. + R-1^ ( x-l+1 + R-1^ x-l )….)))

Integer part Fractional part

x-1 R-1^ ( x-2 + R-1^ (….. + R-1^ ( x-l+1 + R-1^ x-l )….))

x-2 R-1^ (….. + R-1^ ( x-l+1 + R-1^ x-l )….) …………………………………. x-l+1 (^) R-1 (^) x-l x-l ...

Shortcut for r=bg, R=bG

r=bg^ →→→→ b →→→→ R=bG

4=2^2 →→→→ 2 →→→→ 8=2^3

(2301.302) 4 = (10 11 00 01. 11 00 10) 2 = (261.62) 8

Signed Number Representations

Representations of signed numbers

Signed-magnitude Biased^ Complement

Radix-complement Diminished-radix complement (Digit complement)

Two’s complement One’s complement

r = r =

Biased representation of signed integers

-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

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

R(X) = X + B B = 2 k -1, k =

-2k-1^ ^ X ^2 k-1-

X

R(X)

R

Signed number X

Unsigned Representation R( X )

Bit vector ( xk -1 xk -2... x 0. x -1... x-l )

Binary mapping

Representation mapping

k i i li

R ( X ) x 2

1 ⋅



− =−

Biased representation
with radix 2

Complement Signed Number Representations

Signed number X

Unsigned Representation R( X )

Bit vector ( xk -1 xk -2... x 0. x -1... x-l )

Binary mapping

Representation mapping

k i i li

R ( X ) x 2

1 ⋅



− =−

Complement representations
with radix 2
One’s Complement Representation
of Signed Numbers

R(X) =

X for X > 0

0 or OC(0) for X = 0

OC(|X|) for X < 0

For –(2 k-1^ – 2 -l ) ≤ X ≤ 2 k-1^ – 2 -l

0 ≤ R(X) ≤ 2 k^ – 2 -l

def

One’s complement representation of signed integers

-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

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

X

X >0 (^0) k = X < 0, X +2 k -1 = 2 k -1 - | X | 2 k -

One’s complement representation of signed numbers
Two’s complement transformation (1)
A + 2- l^ = 2 k^ – A for A > 0
For k i

i l

A Ai 2

1

−

=−

def

Properties:

TC( A ) =

0 for A = 0

0 ≤ TC( A ) ≤ 2 k^ – 2- l

TC(TC( A )) = A

2 k^ – A = 2 k^ – A – 2 -l^ + 2 -l^ =

= ( 2 k^ – 2 -l^ – A )+2 -l^ = A + 2 -l

Two’s complement representation of signed integers

-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

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

X

X >0 (^0) k = X < (^0) X +2 k^ = 2 k^ - | X |

Two’s complement representation of signed integers
Signed-magnitude representation of signed numbers

-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

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

X

X >0 0 X <0 k = 0, | X| +2 k -1 (^) = -X +2 k - 2 k -

Signed-magnitude representation of signed numbers