I have this code to convert byte[]to float[].
public float[] ConvertByteToFloat(byte[] array)
{
float[] floatArr = new float[array.Length / sizeof(float)];
int index = 0;
for (int i = 0; i < floatArr.Length; i++)
{
floatArr[i] = BitConverter.ToSingle(array, index);
index += sizeof(float);
}
return floatArr;
}
The problem is that I usually get the result NaN! Why should it be? I checked if the data is in byte[]and the data seems beautiful. If this helps, example values:
new byte[] {
231,
255,
235,
255,
}
But this returns NaN(Not a Number) after converting to float. What could be the problem? Are there other ways to convert byte[]to float[]? I am sure that the values read into the buffer are correct, since I compared them with my other program (which performs amplification for a WAV file).
source
share