Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

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...