IEE754算法
阿新 • • 發佈:2019-01-29
con pub code span convert str 16進制 pan pre
C# IEE754算法,儀表設備經常用的數據指令.16進制轉10進制,10進制轉16進制互轉.留作備份,並發給剛入門工控的人.
算法原理很多人都解釋啦,在此就不多說啦,時間有限,上來就幹!
public static class IEE754Method { public static float HexToFloat(this string hexValue) { try { uint uintValue = Convert.ToUInt32(hexValue, 16);byte[] bytesValue = BitConverter.GetBytes(uintValue); float floatValue = BitConverter.ToSingle(bytesValue, 0); return floatValue; } catch { throw; } } public static string FloatToHex(this floatfloatValue) { try { byte[] bytesValue = BitConverter.GetBytes(floatValue); int intValue = BitConverter.ToInt32(bytesValue, 0); return intValue.ToString("X8"); } catch {throw; } } }
IEE754算法