If the initial value is 2.0 it should output 40000000 and so on.
Does anyone know how to program this in Java?
String floatinput = "2";
float x = Float.valueOf(floatinput).floatValue();
System.out.println((Float.toHexString(x)); // fails (result is: 0x1.0p1 but we wanted 40000000)
Try Float.floatToIntBits(float value)
This will turn 2.0 into the integer 1073741824, or 0x40000000. From there you probably need some sort of Integer.ToHexString to finish the job.
The problem with languages like Java is that they're so high level it becomes severely awkward to try and do things that are otherwise simple in lower-level languages, such as this relatively trivial type-casting.
Quote from: dcx2 on July 06, 2012, 09:09:00 PM
Try Float.floatToIntBits(float value)
This will turn 2.0 into the integer 1073741824, or 0x40000000. From there you probably need some sort of Integer.ToHexString to finish the job.
really awesome, that works. ;D