Tor Henrik Hovi Posted November 12, 2003 Posted November 12, 2003 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...... Quote
Administrators PlausiblyDamp Posted November 12, 2003 Administrators Posted November 12, 2003 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Tor Henrik Hovi Posted November 13, 2003 Author Posted November 13, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.