十六进制转换浮动 [英] hex to float conversion
本文介绍了十六进制转换浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个4字节的十六进制数字:
I have a 4 byte hex number:
08fdc941
应该convrted一个浮点数:25.25,但我不知道怎么样?我使用C#
it should be convrted to a float number: 25.25, but I don't know how? I use C#
什么是从十六进制转换为浮动的正确方法是什么?
what is the correct way of converting from hex to float?
推荐答案
事情是这样的:
byte[] bytes = BitConverter.GetBytes(0x08fdc941);
if (BitConverter.IsLittleEndian)
{
bytes = bytes.Reverse().ToArray();
}
float myFloat = BitConverter.ToSingle(bytes, 0);
这篇关于十六进制转换浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文