Machine Number Systems Fixed radix Positional - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Machine Number Systems Fixed radix Positional

Description:

Machine Number Systems (Fixed radix Positional) Fixed Point Number Representation ... Left Shift Multiply Number by radix r. Right Shift Divide Number by radix r ... – PowerPoint PPT presentation

Number of Views:115
Avg rating:3.0/5.0
Slides: 18
Provided by: alaaeld
Category:

less

Transcript and Presenter's Notes

Title: Machine Number Systems Fixed radix Positional


1
Review - Outline
Dr. Alaaeldin A. Amin Computer Engineering
Department E-mail amin_at_ccse.kfupm.edu.sa http//
www.ccse.kfupm.edu.sa/amin
  • Machine Number Systems (Fixed radix Positional)
  • Fixed Point Number Representation
  • Base Conversion
  • Representation of Signed Numbers
  • Signed Magnitude (Sign and Magnitude)
  • Complement Representation
  • Radix Complement (2s Complement)
  • Diminished Radix Complement
  • Precision Extension
  • Arithmetic Shifts

2
Machine Number Systems?
  • X xk-1 xk-2 ... x1 x0 . x-1 x-2 ... x-m
  • Since Numbers Are Stored in Registers of Fixed
    Length
  • There is a Finite Number of Distinct Values that
    Can be Represented in a Register
  • Let Xmax Xmin Denote The Largest Smallest
    Representable Numbers
  • Xmax rk-1 For an Integral of k-Digits
  • Xmax 1 - r -m For a Fractional of m-Digits
  • Xmax rk - r -m For a of k- Integral Digits
    and m- Fractional Digits
  • Xmin 0
  • Number of Possible Distinct Values r km

Fractional Part
Integral Part
3
Number Radix Conversion
  • Let X be an Integer ? XB in Radix B System
  • ? XA in Radix A
    System
  • Assumptions
  • XB has n digits
  • XB (bn-1..b2 b1 b0)B ,
  • where bi is a digit in radix B system,
  • i.e. bi ? 0, 1, .. , B-1
  • XA has m digits
  • XA (am-1..a2 a1 a0)A
  • where ai is a digit in radix A system,
  • i.e. ai ? 0, 1, .., A-1
  • Problem Statement
  • XB (bn-1..b2 b1 b0)B ? (am-1..a2 a1 a0)A

Unknowns
Knowns
4
  • XB am-1Am-1 a2A2 a1A1 a0A0
  • Where ai ? 0-(A-1)
  • Accordingly, dividing XB by A, the remainder will
    be a0.
  • XB Q0.Aa0
  • Where, Q0 am-1Am-2 a2A1 a1A0
  • Likewise ? Q0 Q1Aa1 ? Get a1
  • Q1 Q2Aa2 ? Get a2
  • Qm-3 Qm-2Aam-2 ? Get am-2
  • Qm-2 Qm-1Aam-1 ? Get am-1
  • Where Qm-1 0 ? Stopping Criteria

Divisible by A
5
Representation of Signed Numbers
  • Three Main Systems
  • 1. Signed Magnitude (Sign and Magnitude)
  • 2. Complement Representation
  • Radix Complement (2s Complement)
  • Diminished Radix Complement
  • Signed Magnitude
  • Independent Representation of The Sign and The
    Magnitude
  • Symmetric Range of Representation
  • -(2n-1 -1) (2n-1 -1)
  • Two Representations for 0 ? 0 , -0
  • ? Nuisance for Implementation
  • Addition/Subtraction Harder To Implement
  • Multiplication Division Less Problematic

6
Representation of Signed Numbers
  • Alternatively
  • 0, 1, , (R/2 - 1) ? ive Numbers
  • R/2, R/21, ., (R-1) ? -ive Numbers ? More
    Complex Sign Detection if r not power of 2

7
Representation of Signed Numbers
  • Complement Representation
  • Positive Numbers (N) Are Represented in Exactly
    the Same Way as in Signed Magnitude System
  • Negative Numbers (-N) Are Represented by the
    Complement of N (N)
  • Define the Complement of a number N (N) as
  • N M -N
  • Where M Some Constant
  • This representation satisfies the Basic
    Requirement That
  • -(-N ) ( N ) M- (M-N) N
  • Adding 2 Numbers X (ive) and Y (-ive)
  • IF Y gt X
  • Result Z is -ive, i.e. Complement Represented
  • Z X (M-Y)
  • M -(Y-X) Correct Answer
  • in Complement Form

ive
8
Representation of Signed Numbers
  • IF Y lt X
  • Result Z is ive
  • Z X (M-Y)
  • M (X-Y)
  • Correct Answer X - Y
  • Requirements of M
  • 1- Simple Complement Calculations
  • 2- Simplify/Eliminate Addition Correction Steps
  • Let xi be the Complement of a single Digit xi
  • IF X xk-1 xk-2 ... x1 x0 . x-1 x-2 ...
    x-m
  • Define X xk-1 xk-2 ... x1 x0 . x-1 x-2 ... x-m
  • IF Y lt X
  • Result Z is ive
  • Z X (M-Y)
  • M (X-Y)
  • Correct Answer X - Y
  • Requirements of M
  • 1- Simple Complement Calculations
  • 2- Simplify/Eliminate Addition Correction Steps
  • Let xi be the Complement of a single Digit xi
  • IF X xk-1 xk-2 ... x1 x0 . x-1 x-2 ...
    x-m
  • Define X xk-1 xk-2 ... x1 x0 . x-1 x-2 ... x-m

M Chosen To Eliminate/Simplify Correction Step
9
Representation of Signed Numbers
X xk-1 xk-2 ... x1 x0 . x-1 x-2 ... x-m
X xk-1 xk-2 ... x1 x0 . x-1 x-2 ... x-m
(r-1) (r-1) .. . . (r-1) ulp
1 1 0 0 0 0 . 0 0 ... 0
r k Thus, X X ulp r k
... (1) where ulp unit in least position
r -m (for s with m Fractional
digits) 1 (for INTEGERS, i.e when m0
) Eqn. (1) Can Be ReWritten As r
k - X X ulp (2)
10
Representation of Signed Numbers
  • Radix Complement M r k
  • N r k - N
  • N ulp (Simple Computation)
  • Computing N is independent of k
  • Computing the Previous Addition Requires No
    Corrections
  • Z M (X-Y) r k (X-Y)
  • Diminished Radix Complement M r k - ulp
  • N r k - ulp - N
  • N (Simplest Computation)
  • Computing the Previous Addition Requires Simple
    Correction of Adding ulp
  • Z M (X-Y) r k (X-Y) - ulp

End Around Carry Discarded Added as ulp
Should Add ulp for Correction
11
Representation of Signed Numbers
  • 2s Complement
  • Asymmetric Range of Representation
  • -(2k-1) (2k-1 -ulp)
  • - Negation Can Lead to OverFlow

12
2s Complement Numbers System
  • X xk-1 xk-2 ... x1 x0 . x-1 x-2 ... x-m
  • X if X is ive
  • -2k-1 (2k-1 - X ) X if X is -ive
  • Precision/Range Extension of 2s Comp s
  • Extending N from n-bits to k-bits (kgt k)
  • ive N Pad with 0s to the Left of the
    integral part And/Or to the right of Fractional
    Part.
  • -ive N Pad with 0s to the right of
    Fractional Part And/Or Extend Sign Bit to the
    Left of the integral part.
  • In General
  • Pad with 0s to the right of Fractional Part
    And/Or Extend Sign Bit to the Left of the
    integral part.
  • ...xk-1 xk-1 xk-1 xk-2 ... x1 x0 . x-1 x-2 ....
    x-m 000..

13
2s Complement System
  • Features
  • Leftmost Bit indicates Sign
  • The Sign Bit is Part of a Truncated -String
  • Asymetric Range(-2k-1 (2k-1 -ulp) )
  • Overflow may result on Complementing
  • Single Zero Representation 0000000 (0)

14
Representation of Signed Numbers
  • 1s Complement
  • Symmetric Range of Representation
  • -(2k-1 -ulp) (2k-1 -ulp)
  • - 2 Representations of 0

15
1s Complement Numbers System
  • X xk-1 xk-2 ... x1 x0 . x-1 x-2 ... x-m
  • X for ive X
  • -(2k-1-ulp) X ) X for
    -ive X
  • Precision/Range Extension of 2s Comp s
  • Extending N from n-bits to k-bits (kgt k)
  • ive N Pad with 0s to the Left of the
    integral part And/Or to the right of Fractional
    Part.
  • -ive N Pad with Sign Bit to the right of
    Fractional Part And/Or to the Left of the
    integral part.
  • In General
  • Pad with Sign Bit to the right of Fractional Part
    And/Or to the Left of the integral part.
  • ..xk-1 xk-1 xk-1 xk-2 .. x1 x0 . x-1 x-2 .. x-m
    xk-1 xk-1 ..

16
1s Complement Numbers System
  • Features
  • Leftmost Bit indicates Sign
  • The Sign Bit is Part of a Truncated -String
  • Symetric Range(-(2k-1 -ulp) (2k-1 -ulp) )
  • Two Zero Representation (0 , -0 )

Arithmetic Shifts
  • Effect
  • Left Shift Multiply Number by radix r
  • Right Shift Divide Number by radix r
  • (a) Shifting Unsigned or ive Numbers
  • Shift-In 0s (for both Left Right Shifts)
  • (b) Shifting -ive Numbers
  • Depends on the Representation Method
  • Signed Magnitude
  • Sign Bit is maintained (Unchanged)
  • Only The Magnitude is shifted and 0s are
    Shifted-In for both Directions (Left Right)

17
Arithmetic Shifts
  • 2s Complement
  • Left Shifts 0s are Shifted-In
  • Right Shifts Sign Bit Extended (Shifted Right)
  • 1s Complement
  • Left Right Shifts Sign Bit is Shifted-In

Right Shifts
Left Shifts
Write a Comment
User Comments (0)
About PowerShow.com