十六进制数转换成float类型数据数据的经典代码

最近在研究姿态传感器,发现一段很有意思并实用的代码,再次分享给大家,希望能共同进步

IEEE(Hex 小数和float 转换过程):

下面是转换的程序:
float ByteToFloat(unsigned char* byteArry)//使用取地址的方法进行处理
{
return *((float*)byteArry);
}
void main()
{
unsigned char data[4]={0xc3,0xf5,0x1c,0x41};
float f_data=0;
f_data=ByteToFloat(data);
printf("%f\n",f_data);
}

猜你喜欢

转载自blog.csdn.net/lsg_down/article/details/80687551