La conversión de punto flotante de precisión simple y hexadecimal de cuatro bytes de C# puede usar la función integrada, o puede escribirla usted mismo
Los ejemplos son los siguientes:
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;
}