The conversion from uint
to float
(and reverse) can be done with "safe" code as well (though I don't know if this is possible on the NETMF or not).
[StructLayout(LayoutKind.Explicit)]
struct UIntFloat
{
[FieldOffset(0)]
public float FloatValue;
[FieldOffset(0)]
public uint IntValue;
}
public static float ToSingle(byte[] value, int index)
{
uint i = ToUInt32(value, index);
return ToSingle(i);
}
public static float ToSingle(uint value)
{
UIntFloat uf = new UIntFloat();
uf.IntValue = value;
return uf.FloatValue;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…