problem converting 4-bytes array to float in C#
Your bytes are coming out word-swapped. This function should convert your byte array to floats properly:
static float ToFloat(byte[] input)
{
byte[] newArray = new[] { input[2], input[3], input[0], input[1] };
return BitConverter.ToSingle(newArray, 0);
}
ToFloat(new byte[]{2,73,98,43}) == 533174.1
- How about endianess? Have you tried reversing the word order? In windows, 533174.1 is 98, 43, 2, 73.
- 4 bytes are a single (ToSingle), not double.