converting bytearray to double

Joined
Mar 3, 2003
Messages
9
Location
Norway
Hi all.
Im comunicating with an USB device and are getting values as bytearrays through it.

So I recive a 8 byte long array wich is supposed to be a double variable. How do I convert/typecast those eight bytes into a Double value?
I have found some hints on the net about using a fromstream function. But I cant find out how to do it.

It is probably the same as reading a double value from a file?
If so there should be an easy way of doing this, but I cant find it.

Banging my head against the wall on this one, so any input would be appriciated......
 
the following will get a double from a hard coded byte-array but hopefully it should work with your data

Code:
Dim b() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}

Dim ms As New IO.MemoryStream(b)
Dim sr As New IO.BinaryReader(ms)
Dim d As Double = sr.ReadDouble()

sr.Close()
ms.Close()

not sure if the answer is right but worth a try
 
Thank you VERY much PlausiblyDamp.

Im not quite sure of what this is doing ,but it seems to do the trick, and I can now stop banging my head against he wall.


Really nice of you to take the time to answer my question.
 
Back
Top