I want to convert a byte array containing floats(4 bytes as a float) into a double array in the fastest way possible so I'm using blockcopy as internet suggested it. But , it seems like the values were not correct after the conversion into double can somebody help with!
public static void Test()
{
var floatArray = new float[] { 123.45f, 123f, 45f, 1.2f, 34.5f };
// create a byte array and copy the floats into it...
var byteArray = new byte[floatArray.Length * sizeof(float)];
Buffer.BlockCopy(floatArray, 0, byteArray, 0, byteArray.Length);
// create a double array and copy the bytes into it...
var doubleArray = new double[byteArray.Length / 4];
Buffer.BlockCopy(byteArray, 0, doubleArray, 0, byteArray.Length);
// do we have the same sequence of floats that we started with?
foreach(var i in doubleArray)
{
Console.WriteLine(i);
// outputs --> 387028163194470.4 , 0.02500000981399353 , 5.474008307E-315 , 0 , 0
}
}
