一、16进制转float型
static void Main(string[] args) { string value = "B6798842"; value = "428879B6"; #region Demo1 UInt32 x = Convert.ToUInt32(value, 16);//将字符串转为16进制32位无符号整数 float fy = BitConverter.ToSingle(BitConverter.GetBytes(x), 0); Console.WriteLine("Demo1==>" + fy); #endregion #region Demo2 byte[] bytes = new byte[4]; for (int i = 0; i < 4; i++) { bytes[i] = Convert.ToByte(value.Substring((3 - i) * 2, 2), 16); } float fy2 = BitConverter.ToSingle(bytes, 0); Console.WriteLine("Demo2==>" + fy2); #endregion #region Demo3 value = "B6798842"; byte[] bytes3 = new byte[4]; for (int i = 0; i < 4; i++) { bytes3[i] = Convert.ToByte(value.Substring(i * 2, 2), 16); } float fy3 = BitConverter.ToSingle(bytes3, 0); Console.WriteLine("Demo3==>" + fy3); #endregion Console.ReadLine(); }View Code
其他
标签:Console,进阶,16,float,value,BitConverter,转换,byte,进制 From: https://www.cnblogs.com/chenze-Index/p/17250746.html