Skip to content

Instantly share code, notes, and snippets.

@jinahya
Created March 19, 2016 13:03
Show Gist options
  • Save jinahya/0ab29224afedcb712fff to your computer and use it in GitHub Desktop.
Save jinahya/0ab29224afedcb712fff to your computer and use it in GitHub Desktop.
FloatIntBits.java
public class FloatIntBits {
private static void printIntBits(float value) {
System.out.println("-------------------------------------");
System.out.printf(" value: %f\n", value);
final int intBits = Float.floatToIntBits(value);
final int rawIntBits = Float.floatToRawIntBits(value);
System.out.printf(" toIntBits: 0x%08x %f\n", intBits, Float.intBitsToFloat(intBits));
System.out.printf("toRawIntBits: 0x%08x %f\n", rawIntBits, Float.intBitsToFloat(rawIntBits));
}
public static void main(final String... args) {
printIntBits(3.14f);
printIntBits(Float.NaN);
final float SNaN = Float.intBitsToFloat(0b0_11111111_01000000000000000000000);
final float QNaN = Float.intBitsToFloat(0b0_11111111_11000000000000000000000);
printIntBits(SNaN);
printIntBits(QNaN);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment