十六进制字符串转成float 十六位字符串 42363333 (左高右低)刚才自己做了一会没做出来 求解 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Console.Write(int.Parse("42363333",System.Globalization.NumberStyles.HexNumber)); Console.WriteLine( float.Parse(Convert.ToInt32("42363333", 16).ToString())); 这么写吧0x42 0x36 0x33 0x33 (左高右低) 计算后的float应该是45.55 public string FloatToHex(float floatValue){ uint uintValue = BitConverter.ToUInt32(BitConverter.GetBytes(floatValue), 0); byte[] byteValue = BitConverter.GetBytes(uintValue); Array.Reverse(byteValue); return BitConverter.ToString(byteValue).Replace("-","");}public float HexToFloat(String hexString){ uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier); byte[] floatVals = BitConverter.GetBytes(num); return BitConverter.ToSingle(floatVals, 0);} 5 楼正确,5楼是按照我们常人习惯的读写顺序进行hex转换的。楼主hex2byte那贴,一二楼是按照.net 内部 高低位做的转换,理解上可能困难些。 这个更书本化、正统一些。 请问这种格式如何提取openid的值 怎么限制别人执行程序 关于NumericUpDown的问题 求一个SQL语句 关于treeview的问题。急 DataTable 是引用传递??我一直没有怀疑,谁能解释以下问题 简单问题,解决马上揭帖.. 变量值的刷新问题 在win窗体中DataGrid如何得到当前选中行第一列的值 自动点击treeview的方法。(急!) vs2005项目中如何查看哪些函数未被调用? 求正则表达式:只能输入数字或者为空
Console.WriteLine( float.Parse(Convert.ToInt32("42363333", 16).ToString()));
计算后的float应该是45.55
public string FloatToHex(float floatValue)
{
uint uintValue = BitConverter.ToUInt32(BitConverter.GetBytes(floatValue), 0);
byte[] byteValue = BitConverter.GetBytes(uintValue);
Array.Reverse(byteValue);
return BitConverter.ToString(byteValue).Replace("-","");
}public float HexToFloat(String hexString)
{
uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
return BitConverter.ToSingle(floatVals, 0);
}
楼主hex2byte那贴,一二楼是按照.net 内部 高低位做的转换,理解上可能困难些。
这个更书本化、正统一些。