.net converting bytearray to double []
I am working with a database from a legacy application that stores 24 floating point values (doubles) as a 192 byte array, so 8 bytes per value. This byte array is stored in a type column image
in a SQL Server 2005 database.
In my .net application, I need to read this byte array and convert it to an array of type Double[24]
. I can easily access the field reader.GetBytes(...)
, but how do I convert the returned ByteArray
toDouble[24]
Any ideas?
Thank,
AJ
source to share
Well, how is each set of 8 bytes represented? You can use Buffer.BlockCopy
:
double[] doubles = new double[bytes.Length / 8];
Buffer.BlockCopy(bytes, 0, doubles, 0, bytes.Length);
or you may need to reuse BitConverter.ToDouble
- or some custom conversion method.
source to share