Skip to content

Instantly share code, notes, and snippets.

@TheB1ackSheep
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheB1ackSheep/8788678 to your computer and use it in GitHub Desktop.
Save TheB1ackSheep/8788678 to your computer and use it in GitHub Desktop.
public class FloatingPointRep {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Enter you float (eg. 135.00, -50.65): ");
float _f1 = sc.nextFloat();
String _f1Bin = Integer.toBinaryString(((Float) _f1).hashCode());
System.out.printf("The value of _f1 is %f\n", _f1);
System.out.printf("The bin representation of _f1 is %s\n\n", padding(_f1Bin));
//System.in.read();
}
private static String padding(String value) {
if (value.length() < 32) {
value = String.format("%32s", value).replace(' ', '0');
}
return value.substring(0, 1) + " " + value.substring(1, 9) + " " + value.substring(9, 32);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment