Download 02-Signed-Number Representation

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Fixed-Point Negative Numbers
Two Common Forms:
1. Signed-Magnitude Form
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
Signed-Magnitude Example
n7
k 4
k 1  3
m3
s  2
d  10
1101.1102  1  (1  22  1  20  1  2 1  1  2 2 )10
1 1

 1   4  1     5.7510
2 4 10

Largest Representable Value is:
0111.1112  1 (1 22  1 21  1 20  1 21  1 22  1 23 )10
1 1 1

 7
 1  4  2  1        7 
2 4 8 10

 8 10
Signed-Magnitude Example (cont)
n7
k 4
k 1  3
m3
s  2
d  10
0111.111  1  (1  22  1  21  1  20  1  2 1  1  2 2  1  2 3 )10
1 1 1

 7
 1   4  2  1        7 
2 4 8 10

 8 10
1 ulp  1  2 3 
1
8
k  1  3,
 s k 1  23  8
1
1 ulp  (  s ) 
8
X MAX   k 1  ulp
X MIN  1  (  k 1  ulp )
X  [ X MIN , X MAX ]
m 1
Signed-Magnitude Ternary Example
n7
k 4
k 1  3 m  3
xi  {0,1,2}
s  3
d  10
2102.120  1 (1 32  2  30  1 31  2  32 )10
1 2

 5
 1  9  2      11 
3 9 10

 9 10
 (11.555555 )10
Notice that fractional part is infinite in =10 but finite in =3
1
m 1
1 ulp  min{xi  0}  (  s ) 
27
X MAX   k 1  ulp
X MIN  1  (  k 1  ulp )
X  [ X MIN , X MAX ]
Signed-Magnitude Ternary Bounds
n7
k 4
k 1  3 m  3
xi  {0,1,2}
s  3
d  10
X MAX  0(   1)(   1)(   1).(   1)(   1)(   1)
 0222.2223  1  (2  32  2  31  2  30  2  31  2  32  2  33 )10
2 2 2 
26

 1   18  6  2      26
3 9 27 10
27

1
k 1
   ulp  27 
27
k 1
[

0,

 ulp]
Positive Numbers:
k 1
Negative Numbers: [(   ulp), 0]
Range:
[(  k 1  ulp),  k 1  ulp]
Signed-Magnitude Comments
• Two Representations for zero, +0 and –0
• Addition of +K and –K is not zero
EXAMPLE
10001010.002
+00001010.002
10010100.002
-1010+1010 Yields a Sum of –2010!!!!!
• Disadvantage since algorithm requires comparison
of signs and, if different, comparison of magnitudes
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
•
X is Positive, Y is Negative, Compute X + Y
Using Complement Representation
X  ( R  Y )  [ X  ( R  Y )]
 [ R  Y  X ]
 R  (Y  X )
•
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
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
xi  (   1)  xi
•
Definition of Digit Complement for a Word, X
X  ( xk 1xk 2
x m )
Complementation Value, R
•
Add Word and Complement Together:
X  ( xk 1
xk  2
x m ) 
 X  ( xk 1
xk  2
x m ) 
(   1)(   1)
ulp
0
0
1
Now Add
1 ulp
•
0
(   1)
1
0
Therefore, we see that:
X  X  ulp   k
 k  X  X  ulp
0
Answer to
Addition
Radix-Complement Form
•
The Radix Complement Form is Defined When:
R  k
R  X   k  X  X  ulp
•
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   k
 k  X  X  ulp
Radix-Complement Form (cont)
•
No Correction is Needed When We have Positive X and
Negative Y Such That:
X  (R  Y )  0
•
Since R= k
X  (R  Y )  R  ( X  Y )
  k  X Y
•
And  k is discarded Due to Finite Register Length
Radix-Complement Example
 2
k n4
•
Since n = m + k  m = 0
•
Therefore 1 ulp = 20 = 1
•
Given X, the radix complement (2’s complement) is:
R  X   k  X  X  ulp  X  1
•
Range of Positive Numbers is [0000,0111]
•
2’s Complement of Largest, 0111:
X  1000;
•
X  1  10012  710
In Radix Complement, There is a Single Representation of Zero
(0000) and Each Positive Number has Corresponding Negative
Number With MSB=1
Radix-Complement Example
 2
•
k n4
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,
0010 (210 )
0111 (710 )
1001 ( 710 )
 1110 ( 210 )
0 1011 ( 510 )
1 0101 (510 )
-810X+710
1011  0100  0100  1  0101 ( decode)
Same to Encode
Diminished-Radix Complement
 2
•
k n4
In Diminished Radix Complement, the Complementation
Process is Easier Since the Addition of 1 ulp is Avoided
R   k  ulp
R  X   k  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  X  7
•
In All Cases MSB is Sign Bit
Comparison of Two’s Complement, One’s
Complement and Signed-Magnitude
Sequence
011
010
001
000
111
110
101
100
Two’s
One’s
Complement Complement
3
3
2
2
1
1
0
0
-1
-0
-2
-1
-3
-2
-4
-3
SignedMagnitude
3
2
1
0
-3
-2
-1
-0
Signed-Number Arithmetic
• Signed Magnitude – Only Use Magnitude Digits
0
1011 (1110 )
0
0110 (  610 )
1
0001 (  110 )
Carry-out
 Overflow
Radix-Complement Arithmetic
n5
X  1310
k 5
 2
Y  810
X Y  ?
•Radix Complement; In this case 2’s Complement
01101 (1310 )
11000 ( 810 )
100101
( 510 )
Carry-out
Does NOT Mean
Overflow
2’s-Complement Overflow
•If X, Y have opposite signs overflow never occurs
whether carry-out exists or not
00101 ( 510 )
01010 ( 1010 )
10110 (  1010 )
11011 ( 510 )
( 510 )
1 00101 ( 510 )
11011
No
Carry-out
•If X, Y have same sign and result sign differs,
overflow occurs
11001 ( 710 )
10110 (  1010 )
1 01111 (  1510 )
Carry-out, Overflow
Carry-out
00111 ( 710 )
01010 ( 1010 )
10001
( 1510 )
No
Carry-out,
Overflow
1’s-Complement Overflow
• One’s complement – carry-out indicates a correction
is needed
X
 Y NegativeValue
Positive Value;
Y  R Y
R  Y   k  ulp  Y  Y

1' s Complement Definition
X  Y  X  2n  ulp  Y  ( X  Y )  (2n  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
Example of 1’s-Complement Overflow
Need
Correction
Since
Overflow
So-called
“end-around”
carry
01010 ( 1010 )
11010 ( 510 )
1 00100

( 410 )
1 ( ulp)
00101 ( 510 )
“End-Around” Carry Design
Carry-out
• This is “end-around” carry
– always add carry-out to LSD
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
  r
xi  {0,1,
X
k 1

i  m
xi wi 
k 1

i  m
,   1}
xi  
i
k 1

i  m
xi (  r )i
 r i , i even
wi   i
  r , i odd
Nega-decimal example:
r  10
(192) 10  1  (10) 2  9  ( 10)1  2  (10) 0
 100  90  2  1210
(12) 10  1  ( 10)1  2  (10) 0
 10  2  810
Nega-Decimal Number System
Largest Positive Value, Xmax:
X max 
09090909.0909
Smallest Value, Xmin:
X min 
909090.9090
Finite Register Length, n=3 digits:
X  [090,909]
X min  (090) 10  1  (090)10  9010
X max  (909) 10  1  (909)10  90910
Asymmetric System!!!: 10 times more positive than negative
values represented
Nega-Decimal Number System
Finite Register Length, n=4 digits:
X  [9090,0909]
909010  X  90910
Now more Negative Values than Positive
Nega-decimal System Characteristics:
• 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:
   r;
Example
n4
r2
(1010) 2  X  (0101) 2
 1010  X  510
8
0
 1
0
4 2 1 
1 0 1 
1 0 1 
1 1 0 
wi value
0  ( 2)3  1  ( 2) 2  0  ( 2)1  1  ( 2) 0  510
1  ( 2)3  1  ( 2) 2  0  ( 2)1  1  ( 2) 0  310
0  ( 2)3  1  ( 2) 2  1  ( 2)1  0  ( 2) 0  210
How is this Addition Operation Performed?????
Nega-Binary Number System
23 22 21 20
8 4 2 1

Carry-out
0
1
1
0
1
0 0
1 0
1
0
1
1
0
0
1
1
1
1
0
0
0
0
1
1
0
wi Values
(5)10
(-3)10
(1+1=4-2)10
(0+0=0)10
(4+4=16-8)10
(0-8=-8)10
(5-3=2)-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!
Related documents