本文介绍了通过IEEE 754协议转换值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过IEEE 754转换十六进制值
感谢adv ....
How to convert Hex value through IEEE 754
thanks in adv....
推荐答案
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);
}
}
祝你好运!
来自此页面:
[]
public float GetFloatIEE754(byte[] array)
{
Array.Reverse(array);
return BitConverter.ToSingle(array, 0);
}
这篇关于通过IEEE 754协议转换值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!