fork download
  1. import static java.lang.System.out;
  2.  
  3. class Q2506277Converter {
  4.  
  5. private static strictfp float binary32ToDecimal( String s /* the significand */ ) {
  6.  
  7. byte n = 1; /* the 'n' in the sigma notation */
  8. byte p = 24; /* the 'p' in the sigma notation */
  9. byte bitN = 0; /* the 'bit_n' in the sigma notation */
  10. byte e = 1; /* the 'e' in the sigma notation */
  11. float sum = 0.0f; /* the summation in the sigma notation */
  12.  
  13. for(; n <= p-1; n++ ){
  14. bitN = Byte.parseByte( s.substring( n, n+1 ) );
  15. sum += (float)(bitN * Math.pow(2, -n) ); /* the '2^-n' in the sigma notation */
  16. }
  17.  
  18. return (1 + sum) * (float)Math.pow( 2, e ); /* the '2^1' in the sigma notation */
  19. }
  20.  
  21. public static void main( String[] args ){
  22.  
  23. /* IEEE 754 encoding significand */
  24. String significand = "110010010000111111011011";
  25.  
  26. out.printf( "%.9f%n", binary32ToDecimal( significand ) );
  27. }
  28. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
3.141592741