// Float.floatToIntBits( float ) = Returns a representation of the specified // floating-point value according to the IEEE 754 format public class func_call_conv2 { static float f( int x) { System.out.printf(" f: x = %d , in binary: ", x); printBitInt(x); System.out.println(); float r; r = x*x; System.out.printf(" f: r = %f , in binary: ", r); printBitFloat(r); System.out.println("\n"); return(r); } public static void main(String[] args) { float a; int b; a = 2.0f; System.out.printf("main: a = %f , in binary: ", a); printBitFloat(a); System.out.println("\n"); b = (int) f((int) a); // *** Need 2 casts !!! System.out.printf("main: b = %d , in binary: ", b); printBitInt(b); System.out.println("\n"); } /* ========================================== Bit pattern printing methods... ========================================== */ static void printBitFloat( float x ) { int i; for ( i = 31; i >= 0; i-- ) { if ( (Float.floatToIntBits(x) & (1 << i)) != 0 ) System.out.print("1"); else System.out.print("0"); } } static void printBitInt( int x ) { int i; for ( i = 31; i >= 0; i-- ) { if ( (x & (1 << i)) != 0 ) System.out.print("1"); else System.out.print("0"); } } }