Convert Byte Array to Array of Singles?

  • Thread starter Thread starter elziko
  • Start date Start date
E

elziko

I have a file which, at a certain point, contains 40000 bytes. I need to go
through these bytes and for each four bytes I need to create a singles
ending up with 10000 singles.

This is how I'm doing it:

For i = 0 To 39999
fsNCodeFile.Read(arrBytes, 0, 4)
sngValue = BitConverter.ToSingle(arrBytes, 0)
'do something quick with sngValue
Next

Is there a quicker way to get these singles form the file? I know which byte
in the file to start and finish on and no other data apart from singles is
found between these points.
 
It would be faster to read all the bytes at once and then convert them to
singles. This is a lot better than reading only four bytes at a time.

'-- Read all the bytes
fsNCodeFile.Read(arrBytes, 0, 40000)

'-- Then convert them
For i = 0 to 39999 Step 4
sngValue(count) = BitConverter.ToSingle(arrBytes, i)

count +=1
Next
 
I have a file which, at a certain point, contains 40000 bytes. I need to go
through these bytes and for each four bytes I need to create a singles
ending up with 10000 singles.

This is how I'm doing it:

For i = 0 To 39999
fsNCodeFile.Read(arrBytes, 0, 4)
sngValue = BitConverter.ToSingle(arrBytes, 0)
'do something quick with sngValue
Next

Is there a quicker way to get these singles form the file? I know which byte
in the file to start and finish on and no other data apart from singles is
found between these points.

System.IO.BinaryReader.ReadSingle
 
Back
Top