两种方法:
1.单个float转化为byte[],然后拼起来:
public byte[] FloatArrayToByteArray(float[] floats)
{
if (floats.Length <= 0)
{
return null;
}
byte[] bytes = new byte[floats.Length * 4];
for (int i = 0; i < floats.Length; i++)
{
byte[] b = BitConverter.GetBytes(floats[i]);
bytes[i * 4] = b[0];
bytes[i * 4 + 1] = b[1];
bytes[i * 4 + 2] = b[2];
bytes[i * 4 + 3] = b[3];
}
return bytes;
}
2.byte[] result = resourceArray.SelectMany(x => BitConverter.GetBytes(x)).ToArray();