Link to home
Create AccountLog in
Avatar of grendelJS
grendelJS

asked on

float IEEE 754 to hex

Hi,
I need to convert a float (IEEE 754) to hexdecimal.
Is there a class that do it in C#?
Avatar of smegghead
smegghead
Flag of United Kingdom of Great Britain and Northern Ireland image

Use...

string Res=Convert.ToString(754,16);

the 2nd parameter (16) represents the base.

HTH

Smg.

PS. to convert back to decimal (from hex) - use...

int Res=int.Parse(InHex,NumberStyles.HexNumber)
Avatar of ericgu
ericgu

Are you asking how to get the 4 hex bytes that make up the float?

If so, try BitConverter.GetBytes()
Avatar of grendelJS

ASKER

I'am trying to convert a floating point value (following the IEEE standard 754) 11.0 to this number: 1093664768.
I'am sorry but I'm not sure about the steps I need to do to get the second number.
I've got the solution. A friend of mine, have suggested it.

float a = 11.0F;
uint myUint = BitConverter.ToUInt32(BitConverter.GetBytes(a),0);
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account