Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all.

I'm 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 can't find it.

 

Banging my head against the wall on this one, so any input would be appriciated......

  • Administrators
Posted

the following will get a double from a hard coded byte-array but hopefully it should work with your data

 

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Thank you VERY much PlausiblyDamp.

 

I'm 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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...