How do you get the mantissa of floating point numbers in Java?

I'm trying to get the mantissa of a floating point number (just for learning), but it doesn't work as expected

Say the mantissa of 5.3 is 53, right? I tried this Code:

System.out.println(Float.floatToIntBits(5.3f) & 0x7FFFFF);

It prints 2726298 Should it not delete the index bit and leave 53? I've tried a lot, but it always happens What did I do wrong here?

Solution

The single precision formula in accordance with IEEE standard is:

(-1)^sign + 1.Mantissa x 2^(Exponent - Bias)

So 5.3 base 10 is 101.010011001011 base 2

101.0100110011001100110011 = 1.010100110011001100110011 * 2 ^ 2

2 ^ 2 = 2 ^ (Exp – deviation) with deviation = 127 (according to IEEE single precision standard) so: exp – 127 = 2 = > exp = 129 base 10 or 10000001 base 2

Single precision table:

0 | 10000001 | 01010011001100110011001

Sign = 0exp = 129 mantissa = 2726297

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>