Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the output of the native Float.floatToRawIntBits(float value)?

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?

like image 421
Jivings Avatar asked Jan 26 '12 16:01

Jivings


1 Answers

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

like image 107
benfrasersimpson Avatar answered Sep 26 '22 16:09

benfrasersimpson