通过IEEE 754协议转换值 [英] Convert value by IEEE 754 protocol

查看:93
本文介绍了通过IEEE 754协议转换值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过IEEE 754转换十六进制值



感谢adv ....

How to convert Hex value through IEEE 754

thanks in adv....

推荐答案

像这样:



Like this:

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);
          }
      }







祝你好运!



来自此页面:

http://weblogs.asp.net/craigg/archive/2006/09/25/Hexadecimal-to-Floating-Point-_2800_IEEE-754_2900_.aspx [ ^ ]


public float GetFloatIEE754(byte[] array)
{
Array.Reverse(array);
return BitConverter.ToSingle(array, 0);
}


这篇关于通过IEEE 754协议转换值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆