Page 1 of 1
Writing float values to hex
Posted: Tue Jan 17, 2006 7:00 pm
by Klaz0r
Ok, I've seen the binary representation of a floating point number, and let me just say it's not pretty. Is there a simpler way to convert a floating point number into its hexadecimal equivalent without having to find out mantissas and 2s compliments and stuff? It would really help if I could get this in VB code.
Posted: Tue Jan 17, 2006 7:52 pm
by Onetoomanysodas
Animated Siggy!
Posted: Tue Jan 17, 2006 8:20 pm
by Klaz0r
Fine, I'll change it, but still, I need to figure this out
Posted: Wed Jan 18, 2006 2:43 pm
by modder4321
wats ur aim klazor i will help u with this
Posted: Sun Jan 22, 2006 3:38 am
by kornman00
If your using .Net:
Code: Select all
public static void GetBytesSingle( float argument )
{
const string formatter = "{0,16:E7}{1,20}";
byte[] byteArray = BitConverter.GetBytes( argument );
Console.WriteLine( formatter, argument, BitConverter.ToString(byteArray) );
}
GetBytesSingle( 1.0F ); // outputs "00-00-80-3F"
GetBytesSingle( 15.0F ); // outputs "00-00-70-41"
If your using C\C++ you can just type cast it to a long and use itoa to get the hex value in a string
If you using VB6. I recommend you upgrade to VB.NET or even better, C#.NET