public class OurFloatDemo { public static void main(String[] args){ System.out.println(OurFloat.getIEEEBits(2.0F)); System.out.println(OurFloat.getIEEEBits(1.0F)); System.out.println(OurFloat.getIEEEBits(-2.0F)); System.out.println(OurFloat.getIEEEBits(-1.0F)); System.out.println(OurFloat.getIEEEBits((float)Math.PI)); System.out.println(OurFloat.getIEEEBits(0.1F)); System.out.println(OurFloat.getIEEEBits(0.0F)); System.out.println(1.0F/0.0F); System.out.println(OurFloat.getIEEEBits(1.0F/0.0F)); System.out.println(0.0F/0.0F); System.out.println(OurFloat.getIEEEBits(0.0F/0.0F)); } } class OurFloat{ // given a float, return a bitstring showing the // internal IEEE representation as 32 bits static String getIEEEBits(float x){ // Float.floatToIntBits converts a float to // the internal IEEE representation but stored as // an int, which we then need to convert to a // binary string String s = Integer.toBinaryString(Float.floatToIntBits(x)); while(s.length() < 32){ // need to prepend 0s s = "0" + s; } return s; } }