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#?
C#

Avatar of undefined
Last Comment
CetusMOD

8/22/2022 - Mon
smegghead

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)
ericgu

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

If so, try BitConverter.GetBytes()
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 started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
grendelJS

ASKER
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
CetusMOD

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.