Reputation: 18068
I have used that site: http://sandbox.mc.edu/~bennet/cs110/flt/dtof.html they say that 2.625
is 0_100_0101
based on that the exponent is 4
and mantisa is 5/16
. So the number is (5/16) * 2^4
and this is definetly not 2.625
.
So how it should be.
Upvotes: 2
Views: 28695
Reputation: 3286
You are interpreting your data in a wrong way.
0 is the sign, so the number is positive 100 is the exponent which is in fact 1 (2^1). The exponent is signed and the possible values are:
000 (the number 0, and denormalised numbers)
001 -2
010 -1
011 0
100 1
101 2
110 3
111 (infinities and NANs)
P.S. NAN : not a number (error codes and stuff)
0101 is your mantissa.
What this in fact means is that your number is 1.0101 (there's a hidden bit for extra precision since every number must start with "1." that "1" is not actually stored).
This gives you (1+5/16)*2 = 2.625
Upvotes: 5
Reputation: 385
[Expanding on JasonD's answer]
I think it's safe to assume that you understand, or rather take for granted, that a float can have a negative exponent.
But if you come to think about it, how does that actually happen? That's where the 'bias' comes to play, and I think that's the missing link in your understanding. In your link, they mentioned the following law for calculating the bias:
2^(k-1) - 1
Where k is the number of bits in the exponent field. In your example, k was 3 bits, so the bias is 3. This way you can encode any exponent in the range [-3,4] (inclusive).
So now it's hopefully clear that when you're decoding the number, you have to 'unbias' the exponent first. So your 2^4 is actually 2^1 as JasonD stated.
Upvotes: 1
Reputation: 473
The Floating Point Number is 45 (Base 16) i.e. 01000101 (Base 2)..
0101 is the mantissa part and 100 is the exponent one...
On restoring the leading one the mantissa is renewed to 1.0101...
Subtracting the bias from the exponent, which is 3 in case of 8-bit representation, the exponent becomes 1...
The Binary representation is 1.0101 * 2^1...
De-normalizing we get 10.101, which is the binary representation for 2.625...
Upvotes: 1
Reputation: 16612
The most significant '1' is not encoded. So you need to add that on when converting.
In this case, the digits are '0101', so adding a '1' would give '1.0101'. Then the exponent is 4, but needs to be offset by 3, so the actual multiplier is just 2^1.
That gives a result of '10.101' which is indeed 2.625
Upvotes: 4