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;}