WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: Bully@Wiiplaza on July 06, 2012, 08:47:53 PM

Title: Converting Float to Hex String
Post by: Bully@Wiiplaza on July 06, 2012, 08:47:53 PM
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)

Title: Re: Converting Float to Hex String
Post by: 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.

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.
Title: Re: Converting Float to Hex String
Post by: Bully@Wiiplaza on July 07, 2012, 09:40:01 AM
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