0

I got a HEX FLOAT IEEE 754 data, example "0x0017A8A6", how do I get it to decimal "1550502" in C#.

I got 2 working online converters, but cant get the decimal value, only "2.172716E-39" http://www.h-schmidt.net/FloatConverter/IEEE754.html http://www.binaryconvert.com/convert_signed_int.html?hexadecimal=0017A8A6

Thanks.

hostmit
  • 73
  • 6
  • 2
    Decimal and Float are different - which do you want? 1550502 is the Base-10 _integer_ representation of that hex number, which is different than both. – D Stanley Mar 24 '16 at 19:20
  • Possible duplicate of [How to get the IEEE 754 binary representation of a float in C#](http://stackoverflow.com/questions/4249414/how-to-get-the-ieee-754-binary-representation-of-a-float-in-c-sharp) – Ashraf Sada Mar 24 '16 at 20:34

1 Answers1

1

You can parse a Hex-String (without the leading 0x) in C# by using the following line:

int test = Int32.Parse("0017A8A6", NumberStyles.HexNumber);

However if that Bit-Pattern is interpreted as IEEE754 it has a different meaning and that meaning is "2.172716E-39".

The last 15 bits are the Mantissa (which can be thought of as the number) and the next 8 bits are the exponent that is used to scale the mantissa. Finally the last bit is the sign bit.

Oliver Ulm
  • 531
  • 3
  • 8