Floating point binary representation

91 views Asked by At

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?

1

There are 1 answers

0
Simon Byrne On

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:

1|01111100|00100100100100100100101

where:

  1. the sign is negative, so the sign bit is 1 (1 bit)
  2. 124 in binary 01111100 (8 bits)
  3. we drop the implicit leading 1 from the significand (23 bits)