Created
March 19, 2016 13:03
-
-
Save jinahya/0ab29224afedcb712fff to your computer and use it in GitHub Desktop.
FloatIntBits.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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