How to convert a Byte array to a double array???

A

antonio matos

hi people.

I have to acess a database, and there are some fields that
are binary. when i acess that field is read like an array
of bytes.

but in reality it's an array of doubles!!!

how can i convert from a byte array to a double array?

ps: in C this is SO easy
 
B

Brian

Try this out:

Dim test() As Byte = {23, 45, 78, 98, 101, 157, 158, 162, 178}

Dim dble(8) As Double

Array.Copy(test, dble, 9)
 
B

Brian

Also, if you want to change 8 bytes into a double you can you the
Bitcoverter class:

Dim j() As Byte = {2, 4, 78, 12, 99, 111, 45, 156}
Dim r As Double = BitConverter.ToDouble(j, 0)


Or , you can put this into a loop to covert a Byte array to double values.

Dim m as Integer = j.Length \ 8
Dim dble(m-1) as Double
Dim k as Integer = 0

For i = 0 to j.Length -1 Step 8

dble(k)= BitConverter.ToDouble(j, i)
k +=1

Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top