Leaders snarfblam Posted April 20, 2004 Leaders Posted April 20, 2004 I am making a program that deals with information in bytes. The majority of data is stored in byte arrays, and written to and read from files from byte arrays. Some of this data is Int16s, Int32s, Int64s, singles, and doubles. I need to also store these in and retrieve these from my byte arrays. That means I need the actual binary representations of the values these variables will contain. Were I programming in C++, I could use a union with a byte[2] and Int16, a byte[4] and and Int32, etc. VB lacks such incredibly nifty tools, however, and I must use another means of retrieving the binary data within these variables. I can create functions to do this for me with integers, however at a performance cost. I am not interested in attempting to do this with floating point variables. THE QUESTION: Is there a way in VB to convert, say, a single into a byte[4]? Or a way to write a single into a byte array? Or any other process not overly complex to get the binary data from any of these simple data types? The only solution that has occurred to me so far is to write the single to a binary access file and read it back as a byte array. This entails more complexity and performance cost than I hope my ultimate solution to have, but illustrates the desired effect. Any suggestions will be greatly appreciated. Quote [sIGPIC]e[/sIGPIC]
Leaders snarfblam Posted April 20, 2004 Author Leaders Posted April 20, 2004 Hey, guess what I just found! The BitConverter class. Quote [sIGPIC]e[/sIGPIC]
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.