fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println(fromFloatTo64Binary("11.1"));
  13. System.out.println(fromFloatTo64Binary("-11.1"));
  14.  
  15. }
  16.  
  17. public static String fromFloatTo64Binary(String input) {
  18.  
  19. input = input.replaceAll(",", ".");
  20.  
  21. double number = Double.parseDouble(input);
  22. long longBits = Double.doubleToLongBits(number);
  23. String result = Long.toBinaryString(longBits);
  24. StringBuilder builder = new StringBuilder();
  25. for (int i = result.length(); i < 64; i++) {
  26. builder.append('0');
  27. }
  28. return builder.append(result).toString();
  29. }
  30.  
  31. }
Success #stdin #stdout 0.1s 320256KB
stdin
Standard input is empty
stdout
0100000000100110001100110011001100110011001100110011001100110011
1100000000100110001100110011001100110011001100110011001100110011