Operations basically the same as integer operations. Users have to keep track of the binary point.
Leftmost bit is sign-bit
S = bk is the sign bit, 0 => value positive, 1 => value negative
bi = 0 or 1
Value of X
and discarding any carry left to bk
( i.e. To obtain the 2s complement of a binary number, we perform a 1s complement and add 1 to the least significant bit )
So
where p ≤ m and b-p is the first nonzero bit in the X representation
One can show that V(-X) = -V(X)
Note also that the 2s complement of the 2s complement of a number is itself.
i.e. -(-X) = X
Examples
A = 0 0 0 0 1 0 0 1
V(A) = 9
-A = 1 1 1 1 0 1 1 1
V(-A) = -V(A) = -9
Suppose bit 7 is sign-bit, binary point is between bit 7 and bit 6
F = 0 . 0 1 0 0 0 0 0
V(F) = 2-2 = 0.25
X = -F = 1 . 1 1 0 0 0 0 0
V(X) = V(-F) = -V(F) = - ( 0 . 0 1 0 0 0 0 ) = - 0.25
Alternative view :
Suppose the binary point is between bit 4 and bit 3; leftmost bit ( bit 7 ) is the sign-bit
R = 0 1 0 1 . 1 1 0 0
V(R) = 22 + 20 + 2-1 + 2-2
= 3.75
Y = -R = 1 0 1 0 . 0 1 0 0
V(Y) = V(-R) = -V(R) = -5.75
Alternative view :
Typical DSP Operation
V(X)min = -1 ( 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ) ( 8000 Hex )
V(X)max = 1 - 2-15 (0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ) ( 7FFF Hex )
1.15 x 1.15 → 1.30
In fraction mode, a typical DSP processor will left-shift the product one bit, so the product is saved in 1.31 format in a temporary 32-bit register with the binary point between bit 31 and bit 30.
Example:
Consider 0.25 x ( -0.75 )
| 0.25 x ( -0.75 ) | = -( 0.0 1 x 0.11 ) |
| = - 0. 0 0 1 1 | |
| = 1.110 1000 0000 0000 0000 0000 0000 0000 ( 1.31 format ) | |
| = E800 0000 Hex |
| 0.25 x ( -0.75 ) | = 0.0 1 x ( 1.010 1000 .. ) |
| = 1.110 1000 0000 0000 0000 0000 0000 0000 ( 1.31 format ) | |
| = E800 0000 Hex ( note two 1s were shifted in ) |
BSET PSW, 9 ;fraction mode MOV Sx, #2000H MOV Sy, #A000H MRa = Sx * Sy, (SS) |
| MRa1 = E800 H, MRa0 = 0000 H |
Calculate a / b
| a − b |
= | a x | 1 − b |
Let
Algorithm to find α :
i = 0;
α = 0;
αi = 15; //i.e. α = 0.100 0000 0000 0000
one = 215 - 1; //i.e one ~ 0.1111 1111 1111 1111 ~ 1
while ( i ≥ 0 ) {
if ( α * b > one )
αi = 0; //guess too large, reset bit
//else fine, take it
--i;
αi = 1; //try next bit
}
|
e.g. 1/3 ≈ 0.010 1010 1010 1010
i = -1;
α = 2i;
while ( i > -14 ) {
if ( amax * α < 1 ) { //want to increase a to gain precision
--i;
α = α + 2i;
} else { //α too large
α = α - 2i; //reset bit i to 0
--i; //test next bit
α = α + 2i;
}
}
|