Writing float values to hex

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
Klaz0r





Posts: 49
Joined: Tue Jul 27, 2004 2:36 pm

Writing float values to hex

Post 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.
Onetoomanysodas





Posts: 325
Joined: Mon Mar 22, 2004 3:59 pm
Location: Everywhere but nowhere
Contact:

Post by Onetoomanysodas »

Animated Siggy!
Klaz0r





Posts: 49
Joined: Tue Jul 27, 2004 2:36 pm

Post by Klaz0r »

Fine, I'll change it, but still, I need to figure this out
modder4321





Posts: 118
Joined: Wed Mar 30, 2005 5:35 pm

Post by modder4321 »

wats ur aim klazor i will help u with this
User avatar
kornman00




ONI New Age

Posts: 146
Joined: Fri Dec 12, 2003 6:30 pm
Contact:

Post 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
Post Reply