Groovy web console

subscribe to the feed Subscribe
to this
site
IEEE 754 Single Point Precision (via #groovywebconsole)
tweet this snippet Tweet
this
script

IEEE 754 Single Point Precision

Published 2 months ago by Ritchie
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
// Negative Float Example
float fNeg = Float.parseFloat("-10.0");
int bitsNeg = Float.floatToRawIntBits(fNeg);

System.out.println("Negative Example: ");
System.out.println("bits: " + Integer.toBinaryString(bitsNeg));
System.out.println("back to float: " + Float.intBitsToFloat(bitsNeg));
System.out.println();

// Positive Float Example
float fPos = Float.parseFloat("10.0");
int bitsPos = Float.floatToRawIntBits(fPos);

System.out.println("Positive Example: ");
System.out.println("bits: " + Integer.toBinaryString(bitsPos));
System.out.println("back to float: " + Float.intBitsToFloat(bitsPos));