I have tried the below C# code to convert from hex literal to floating point and get the correct result. I wish to input a byte array instead and have that converted to floating point but can't seem to get it right result.
0x4229ec00 is the current format. I need it in byte array format something like...
new byte[]{ 0x01, 0x04, 0x01, 0x60, 0x00, 0x02, 0x70, 0x29}; //current output 42.48
The code looks like:
byte[] bytes = BitConverter.GetBytes(0x4229ec00);
float myFloat = floatConversion(bytes);
public float floatConversion(byte[] bytes)
{
float myFloat = BitConverter.ToSingle(bytes, 0);
return myFloat;
}
Any help would be greatly appreciated. Thank you!
0x01, 0x04, 0x01, 0x60, 0x00, 0x02, 0x70, 0x29floatis indeed 4 bytes, not 8, so if you are converting that 8-byte array to a floating point, it won't be afloatbut adouble.