From: Richard A. DeVenezia on
Is there a way to read an entire file into a float array ?

Suppose 1,000 floats (arrayed 250 rows by 4 columns) are stored in a
4,000 byte file.

Starting from
byte[] data = File.ReadAllBytes ("floatdump.data");

How would I cast or overlay a float array interpretation of the byte
array ?

Thanks!
From: Harlan Messinger on
Richard A. DeVenezia wrote:
> Is there a way to read an entire file into a float array ?
>
> Suppose 1,000 floats (arrayed 250 rows by 4 columns) are stored in a
> 4,000 byte file.
>
> Starting from
> byte[] data = File.ReadAllBytes ("floatdump.data");
>
> How would I cast or overlay a float array interpretation of the byte
> array ?

You can skip the byte array. For an unknown number of floats:

BinaryReader reader = new BinaryReader(new MemoryStream(data));
int floatCount = reader.BaseStream.Length / 4;

float[] floats = new float[floatCount];
for (int i = 0; i < floatCount; i++)
floats[i] = reader.ReadSingle();

reader.Close();

But you can also skip the byte array step:

BinaryReader reader =
new BinaryReader(File.Open("floatdump.data", FileMode.Open));