.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

+2


source to share


2 answers


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.

+4


source


brute force:

double[] doubles = new double[24];   

for (int i=0; i < 24; i++)
{
    for (int j=0; j < 8; j++)
    {
        doubles[i] += bytes[i*8 + j] << j*8;
    }
}

      



If the incorrectness is indicated incorrectly, change the last term from j * 8 to (7-j) * 8;

0


source







All Articles