Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert Hex value through IEEE 754

thanks in adv....
Posted
Updated 5-Aug-10 2:45am
v2

Like this:

C#
private Single ConvertHexToSingle (string hexVal) {
          try {
              int i=0, j=0;
              byte[] bArray = new byte[4];
              for (i = 0; i <= hexVal.Length-1; i += 2) {
                  bArray[j] = Byte.Parse (hexVal[i].ToString() + hexVal[i + 1].ToString(), System.Globalization.NumberStyles.HexNumber);
                  j += 1;
              }
              Array.Reverse (bArray);
              Single s =  BitConverter.ToSingle (bArray, 0);
              return (s);
          } catch (Exception ex) {
              throw new FormatException ("The supplied hex value is either empty or in an incorrect format.  Use the " +
                  "following format: 00000000", ex);
          }
      }



Good luck!

comes from this page by the way:
http://weblogs.asp.net/craigg/archive/2006/09/25/Hexadecimal-to-Floating-Point-_2800_IEEE-754_2900_.aspx[^]
 
Share this answer
 
C#
public float GetFloatIEE754(byte[] array)
{
Array.Reverse(array);
return BitConverter.ToSingle(array, 0);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900