fixed-point negative numbers two common forms: 1.signed-magnitude form 2.complement forms...

29
Fixed-Point Negative Numbers Two Common Forms: 1. Signed-Magnitude Form 2. Complement Forms Signed-Magnitude Numbers rst Digit is Sign Digit, Remaining n-1 are the Magn nvention (binary) 0 is a Positive Sign bit 1 is a Negative Sign bit nvention (non-binary) 0 is a Positive Sign digit -1 is a Negative Sign digit ly 2 • n-1 Digit Sequences are Utilized

Upload: gervase-daniel

Post on 23-Dec-2015

234 views

Category:

Documents


0 download

TRANSCRIPT

Fixed-Point Negative NumbersTwo Common Forms:1. Signed-Magnitude Form2. Complement Forms

Signed-Magnitude Numbers

• First Digit is Sign Digit, Remaining n-1 are the Magnitude• Convention (binary)

– 0 is a Positive Sign bit– 1 is a Negative Sign bit

• Convention (non-binary)– 0 is a Positive Sign digit -1 is a Negative Sign digit

• Only 2 • n-1 Digit Sequences are Utilized

Signed-Magnitude Example

Largest Representable Value is:

2 0 1 22 10

1010

1101.110 1 (1 2 1 2 1 2 1 2 )

1 11 4 1 5.75

2 4

7 4 1 3 3 2 10s dn k k m

2 1 0 1 2 32 10

10 10

0111.111 1 (1 2 1 2 1 2 1 2 1 2 1 2 )

1 1 1 71 4 2 1 7

2 4 8 8

Signed-Magnitude Example (cont)7 4 1 3 3 2 10s dn k k m

2 1 0 1 2 310

10 10

0111.111 1 (1 2 1 2 1 2 1 2 1 2 1 2 )

1 1 1 71 4 2 1 7

2 4 8 8

3 11 1 2

8ulp

1 3

1

1 3, 2 8

11 ( )

8

ks

ms

k

ulp

1

11 ( )

[ , ]

kMAX

kMIN

MIN MAX

X ulp

X ulp

X X X

Signed-Magnitude Ternary Example7 4 1 3 3 3 10s dn k k m

2 0 1 210

10 10

10

2102.120 1 (1 3 2 3 1 3 2 3 )

1 2 51 9 2 11

3 9 9

(11.555555 )

1 11 min{ 0} ( )

27m

i sulp x

1

11 ( )

[ , ]

kMAX

kMIN

MIN MAX

X ulp

X ulp

X X X

{0,1,2}ix

Notice that fractional part is infinite in =10 but finite in =3

Signed-Magnitude Ternary Bounds7 4 1 3 3 3 10s dn k k m

2 1 0 1 2 33 10

10

1

0( 1)( 1)( 1).( 1)( 1)( 1)

0222.222 1 (2 3 2 3 2 3 2 3 2 3 2 3 )

2 2 2 261 18 6 2 26

3 9 27 27

127

27

MAX

k

X

ulp

{0,1,2}ix

Positive Numbers:1[ 0, ]k ulp

Negative Numbers: 1[ ( ), 0]k ulp

Range: 1 1[ ( ), ]k kulp ulp

Signed-Magnitude Comments

• Two Representations for zero, +0 and –0

• Addition of +K and –K is not zero

EXAMPLE

• Disadvantage since algorithm requires comparison

of signs and, if different, comparison of magnitudes

10001010.002

+00001010.002

10010100.002

-1010+1010 Yields a Sum of –2010!!!!!

Complement Representations

• Two Types of Complement Representations

1. Radix Complement (binary – 2’s-complement)

2. Diminished-Radix Complement (binary – 1’s-complement)

• Positive Values Represented Same Way as Signed

Magnitude for Both Types

• Negative Value, -Y, Represented as R-Y Where R is a Constant

• Obeys the Identity: ( ) ( )Y R R Y

R R Y

Y

• Advantage is No Decisions Needed Based on Operand Sign Before Operations are Applied

Complement Representation Example

• If |Y| > X, Then the Answer is R - (Y - X)

• If X > |Y|, Then the Answer Should be X - Y

– But X + (R - Y) = R + (X - Y),

Thus R Must be Discarded!

• Solution is to Choose the Value of R Carefully

( ) [ ( )]

[ ]

( )

X R Y X R Y

R Y X

R Y X

• X is Positive, Y is Negative, Compute X + Y

Using Complement Representation

Requirements for Complementation Value, R

• Select R to Simplify (or Eliminate) Correction for

the X > |Y| Case

• Calculation of Complement of Y or (R-Y) Should be

Simple and Fast

• Definition of Complement for Single Digit, xi

• Definition of Digit Complement for a Word, X

( 1)i ix x

1 2( )k k mX x x x

Complementation Value, R

• Add Word and Complement Together:

1 2

1 2

( )

( )

( 1)( 1) ( 1)

0 0 1

1 0 0 0

k k m

k k m

X x x x

X x x x

ulp

Answer toAddition

Now Add1 ulp • Therefore, we see that:

k

k

X X ulp

X X ulp

Radix-Complement Form

• The Radix Complement Form is Defined When:

• Using k is Convenient Since Storing Result in Register of

Length n Causes MSD of 1 to be Discarded due to Finite

Register Length

• Therefore, it is Easy to Compute the Complement of X by:

1. Take the Digit Complement of X

2. Add 1ulp to Complement

k

k

X X ulp

X X ulp

k

k

R

R X X X ulp

Radix-Complement Form (cont)

• No Correction is Needed When We have Positive X and

Negative Y Such That:

• Since R= k

( ) 0X R Y

( ) ( )k

X R Y R X Y

X Y

• And k is discarded Due to Finite Register Length

Radix-Complement Example

• Since n = m + k m = 0

• Therefore 1 ulp = 20 = 1

• Given X, the radix complement (2’s complement) is:

2 4k n

1kR X X X ulp X

• Range of Positive Numbers is [0000,0111]

• 2’s Complement of Largest, 0111:

2 101000; 1 1001 7X X

• In Radix Complement, There is a Single Representation of Zero

(0000) and Each Positive Number has Corresponding Negative

Number With MSB=1

Radix-Complement Example2 4k n

• In Radix Complement, There is a Single Representation of Zero

(0000) and Each Positive Number has Corresponding Negative

Number With MSB=1

• Accounts for 1(zero)+7(pos.)+7(neg.), But Extra Bit Pattern Left

• One Additional Negative Number, 10002=-810, -810X+710

10 10

10 10

10 10

0010 (2 ) 0111 (7 )

1001 ( 7 ) 1110 ( 2 )

01011 ( 5 ) 1 0101 (5 )

1011 0100 0100 1 0101 ( )decode

Same to Encode

Diminished-Radix Complement2 4k n

• In Diminished Radix Complement, the Complementation

Process is Easier Since the Addition of 1 ulp is Avoidedk

k

R ulp

R X ulp X X

• Range of Positive Numbers is: [00002,01112]=[010,710]

• 1’s Complement of Largest is 10002= -710

• 1’s Complement of Zero is 11112

• Two Representations of Zero!7 7X

• In All Cases MSB is Sign Bit

Comparison of Two’s Complement, One’s Complement and Signed-Magnitude

Sequence Two’s Complement

One’s Complement

Signed-Magnitude

011 3 3 3

010 2 2 2

001 1 1 1

000 0 0 0

111 -1 -0 -3

110 -2 -1 -2

101 -3 -2 -1

100 -4 -3 -0

Signed-Number Arithmetic

• Signed Magnitude – Only Use Magnitude Digits

10

10

10

0 1011 ( 11 )

0 0110 ( 6 )

1 0001 ( 1 )

Carry-out Overflow

Radix-Complement Arithmetic

•Radix Complement; In this case 2’s Complement

10

10

10

01101 ( 13 )

11000 ( 8 )

100101 ( 5 )

Carry-outDoes NOT MeanOverflow

5 5 2n k

10 1013 8 ?X Y X Y

2’s-Complement Overflow•If X, Y have opposite signs overflow never occurs

whether carry-out exists or not

10

10

10

00101 ( 5 )

10110 ( 10 )

11011 ( 5 )

10

10

10

01010 ( 10 )

11011 ( 5 )

1 00101 ( 5 )

•If X, Y have same sign and result sign differs, overflow occurs

10

10

10

11001 ( 7 )

10110 ( 10 )

1 01111 ( 15 )

10

10

10

00111 ( 7 )

01010 ( 10 )

10001 ( 15 )

No Carry-out Carry-out

Carry-out, Overflow

No Carry-out,Overflow

1’s-Complement Overflow• One’s complement – carry-out indicates a correction

is needed

;X Positive Value Y NegativeValue

1'k

Y R Y

R Y ulp Y Y s Complement Definition

2 ( ) (2 )n nX Y X ulp Y X Y ulp

• If X > Y, then answer should be X-Y however; registercontains X-Y-ulp since 2n is carry-out bit, therefore must“correct” by adding 1 ulp

Example of 1’s-Complement Overflow

10

10

10

10

01010 ( 10 )

11010 ( 5 )

100100 ( 4 )

1 ( )

00101 ( 5 )

ulp

So-called “end-around”

carry

NeedCorrection

SinceOverflow

“End-Around” Carry Design

• This is “end-around” carry – always add carry-out to LSD

Carry-out

Other Number Systems

• Binary Number Systems are Most Common

• In terms of building “fast” systems, we should consider:

– Negative Radix

– Signed Digit

– Log (logarithm)

– Signed Log

– Complex Radix

– Mixed Radix

– Residue Number Systems

Negative-Radix Fixed-Position Systems

1 1 1

{0,1, , 1}

( )

,

,

i

k k ki i

i i i ii m i m i m

i

i i

r

x

X x w x x r

r i evenw

r i odd

Nega-decimal example:

2 1 010

10

1 010

10

10

(192) 1 (10) 9 ( 10) 2 (10)

100 90 2 12

(12) 1 ( 10) 2 (10)

10 2 8

r

Nega-Decimal Number System

Finite Register Length, n=3 digits:

max 09090909.0909X

Largest Positive Value, Xmax:

Smallest Value, Xmin:

min 909090.9090X

min 10 10 10

max 10 10 10

[090,909]

(090) 1 (090) 90

(909) 1 (909) 909

X

X

X

Asymmetric System!!!: 10 times more positive than negative values represented

Nega-Decimal Number System

Finite Register Length, n=4 digits:

10 10

[9090,0909]

9090 909

X

X

Nega-decimal System Characteristics:

Now more Negative Values than Positive

• Arithmetic Operations Same Regardless of Sign of Number

• No Signed Digit/Complement Representation Needed

• Sign of X Determined by Position of First Non-zero Digit

Nega-Binary Number System

Negative Radix:

; 2r r

How is this Addition Operation Performed?????

Example2 2

10 10

4 (1010) (0101)

10 5

n X

X

3 2 1 010

3 2 1 010

3 2 1 010

8 4 2 1

0 ( 2) 1 ( 2) 0 ( 2) 1 ( 2) 50 1 0 1

1 ( 2) 1 ( 2) 0 ( 2) 1 ( 2) 31 1 0 1

0 ( 2) 1 ( 2) 1 ( 2) 0 ( 2) 20 1 1 0

iw value

Nega-Binary Number System

3 2 1 02 2 2 2

8 4 2 1

0 1 0 1

1 1 0 1

1 1 0

0 0 0

1 1 0

0 0 1

1 0 0 1 1 0

wi Values

(5)10

(1+1=4-2)10

(0+0=0)10

(4+4=16-8)10

(0-8=-8)10

(5-3=2)-10

Carry-out

(-3)10

Nega-Binary Adder Design

• Individual Adder Cells Produce Two Carry-out Bits

• Design a Circuit at Gate Level for a 4-Digit Nega-Binary Adder

• Hint: Cout Functions Should Look Familiar!