Reputation: 23250
The JRE documentation states that the native function Float.floatToRawIntBits(Float value)
...
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, preserving Not-a-Number (NaN) values.
What is "single format"
bit layout? I've never heard this expression.
I ran an example:
float f = 1;
System.out.println(Float.floatToRawIntBits(f));
Which outputs 1065353216
.
What is this function actually doing?
Upvotes: 6
Views: 1682
Reputation: 126
IEEE 754 floating-point ``single format'' bit layout:
Bit 31 of the result represents the sign of the float; bits 30 to 23 represent the (biased) exponent; bits 22 to 0 represent the mantissa.
The int returned is the integer representation of that 32bit string.
Wikipedia details how to convert a float into IEEE 754. http://en.wikipedia.org/wiki/Single-precision_floating-point_format
Upvotes: 6