Converting Float to Hex String

Started by Bully@Wiiplaza, July 06, 2012, 08:47:53 PM

Previous topic - Next topic

Bully@Wiiplaza

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)

My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

dcx2

#1
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.

Bully@Wiiplaza

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
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully