29
Fixed-Point Negative Numbers Two Common Forms: 1. Si gne d- Ma gnit ude Fo rm 2. 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

02f03 Signed

Embed Size (px)

Citation preview

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 1/29

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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 2/29

Signed-Magnitude Example

Largest Representable Value is:

2 0 1 2

2 10

10

10

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 d n k k m  

2 1 0 1 2 3

2 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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 3/29

Signed-Magnitude Example (cont)7 4 1 3 3 2 10s d n 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

k s

m

s

ulp

  

  

1

11 ( )

[ , ]

k  MAX 

 MIN 

  MIN MAX  

  X ulp

  X ulp

  X X X  

  

  

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 4/29

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

2 0 1 2

10

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 1

1 min{ 0} ( ) 27

m

i sulp x  

1

11 ( )

[ , ]

 MAX 

 MIN 

  MIN MAX  

  X ulp

  X ulp

  X X X  

  

  

{0,1,2}i x

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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 5/29

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

2 1 0 1 2 3

3 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 263 9 27 27

127

27

 MAX 

 X 

ulp

   

  

{0,1,2}i x

Positive Numbers:1

[ 0, ]k 

ulp  

Negative Numbers:1

[ ( ), 0]k 

ulp  

Range:

1 1[ ( ), ]

k k ulp ulp   

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 6/29

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!!!!!

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 7/29

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  

• Advantage is No Decisions Needed Based on Operand

Sign Before Operations are Applied

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 8/29

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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 9/29

Requirements for Complementation Value, R

• Select R to Simplify (or Eliminate) Correction forthe 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 i x x  

1 2( )k k m  X x x x   

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 10/29

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 to

AdditionNow Add1 ulp • Therefore, we see that:

  X X ulp

  X X ulp

  

  

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 11/29

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

  X X ulp

  X X ulp

  

  

 R

  R X X X ulp

    

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 12/29

Radix-Complement Form (cont)

• No Correction is Needed When We have Positive X and

Negative Y Such That:

• Since R=  k 

( ) 0  X R Y  

( ) ( )k 

  X R Y R X Y  

 X Y   

• And   k is discarded Due to Finite Register Length

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 13/29

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  

1k   R X X X ulp X    

• Range of Positive Numbers is [0000,0111]

• 2’s Complement of Largest, 0111:

2 10

1000; 1 1001 7 X X 

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

(0000) and Each Positive Number has Corresponding Negative

Number With MSB=1

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 14/29

Radix-Complement Example

2 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, -810 X +710

10 10

10 10

10 10

0010 (2 ) 0111 (7 )

1001 ( 7 ) 1110 ( 2 )0 1011 ( 5 ) 1 0101 (5 )

1011 0100 0100 1 0101 ( )decode

Same to Encode

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 15/29

Diminished-Radix Complement

2 4k n  

• In Diminished Radix Complement, the Complementation

Process is Easier Since the Addition of 1 ulp is Avoided

  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 7 X 

• In All Cases MSB is Sign Bit

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 16/29

Comparison of Two’s Complement, One’s

Complement and Signed-Magnitude

Sequence Two’sComplement

One’sComplement

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 -2101 -3 -2 -1

100 -4 -3 -0

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 17/29

Signed-Number Arithmetic

• Signed Magnitude – Only Use Magnitude Digits

10

10

10

0 1011 ( 11 )0 0110 ( 6 )

1 0001 ( 1 )

Carry-out

Overflow

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 18/29

Radix-Complement Arithmetic

•Radix Complement; In this case 2’s Complement

10

10

10

01101 ( 13 )

11000 ( 8 )100101 ( 5 )

Carry-out

Does NOT Mean

Overflow

5 5 2n k    10 1013 8 ?  X Y X Y  

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 19/29

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-outCarry-out

Carry-out, Overflow

No

Carry-out,Overflow

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 20/29

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 n

  X Y X ulp Y X Y ulp

• If  X > Y , then answer should be X -Y however; register

contains X -Y -ulp since 2n is carry-out bit, therefore must

“correct” by adding 1 ulp

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 21/29

Example of 1’s-Complement Overflow

10

10

10

10

01010 ( 10 )

11010 ( 5 )

1 00100 ( 4 )

1 ( )

00101 ( 5 )

ulp

So-called

“end-around”

carry

Need

Correction

Since

Overflow

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 22/29

“End-Around” Carry Design

• This is “end-around” carry

 – always add carry-out to LSD

Carry-out

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 23/29

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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 24/29

Negative-Radix Fixed-Position Systems

1 1 1

{0,1, , 1}

( )

,

,

i

k k k i i

i i i i

i m i m i m

i

i i

 x

  X x w x x r  

r i evenwr i odd  

  

  

  

Nega-decimal example:

2 1 0

10

10

1 0

10

10

10

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

100 90 2 12

(12) 1 ( 10) 2 (10)

10 2 8

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 25/29

Nega-Decimal Number System

Finite Register Length, n=3 digits:

max 09090909.0909 X 

Largest Positive Value, X max:

Smallest Value, X min:

min 909090.9090 X 

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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 26/29

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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 27/29

Nega-Binary Number System

Negative Radix:; 2r r   

How is this Addition Operation Performed?????

Example

2 2

10 10

4 (1010) (0101)

10 5

n X 

 X 

3 2 1 0

103 2 1 0

10

3 2 1 0

10

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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 28/29

Nega-Binary Number System

3 2 1 02 2 2 2

8 4 2 1

0 1 0 11 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

8/7/2019 02f03 Signed

http://slidepdf.com/reader/full/02f03-signed 29/29

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!