C#四个字节十六进制与单精度浮点数互转可以使用自带的函数,也可以自己写
实例如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace floatDemo
{
class Program
{
//首先设置:项目->属性->生成->常规->允许不安全代码 勾选即可
//由四个字节的十六机制数组转浮点数 自定义
public static float ToFloat(byte[] data)
{
float a = 0;
byte i;
byte[] x = data;
unsafe
{
void* pf;
fixed (byte* px = x)
{
pf = &a;
for (i = 0; i < data.Length; i++)
{
*((byte*)pf + i) = *(px + i);
}
}
}
return a;
}