Last active
August 29, 2015 13:55
-
-
Save TheB1ackSheep/8788678 to your computer and use it in GitHub Desktop.
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 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