I have a problem understading a floating point representation(Two's placement-sign mantissa exponent), could you check, am I doing right?
-1/7
-1*1/7*2^0=-1*4/7*2^1=-1*4/7*2^2=-1*8/7*2^3
so in binary itd be like:
1 00000011 1.001 001 001 001 001 001 001
1/1357
1*1/1357*2^0=1*2048/1357*2^-11
0 | 11110101 | 1.100 000 100...
-205,34
1,60422*2^7
1| 0000011
1 | ...
My main problem is when to know the exponent is negative, could you give me any tips?
I assume you're talking about
float
(i.e. IEEE754 binary32)?In binary, the exact value is
-1/7 = -1.001001001001001001001001001…2 × 2−3
Firstly, the exponent is in the range [-126,12], so we don't need to worry about underflow or overflow.
We then round the significand to 24 bits:
-1.001001001001001001001012 × 2−3
(note the last bit of the significand is rounded up)
We rewrite the exponent in it's biased form (the exponent bias is 127):
-1.001001001001001001001012 × 2124−127
Then we can read off the bit pattern directly:
where:
1
(1 bit)01111100
(8 bits)