Converting integers and long integers to byte arrays 
Author Message
 Converting integers and long integers to byte arrays

I would like to convert integers (2 bytes) and long integer (4 bytes)
into a byte array. For example for the integer, I end up with an array
of dimension 2.

How can I access the two bytes of say an integer indvidually so that I
can store them in the array.

I would also like to do the reverse, by converting the bytes to their
corresponding integer or long integer.

Please help

Thank you

--
Hani Abu Rahmeh



Thu, 26 Nov 1998 03:00:00 GMT  
 Converting integers and long integers to byte arrays


Quote:
>I would like to convert integers (2 bytes) and long integer (4 bytes)
>into a byte array. For example for the integer, I end up with an array
>of dimension 2.

You don't really mean a two-dimensional array, but an array with two
elements, right?

Two-dimensional arrays look like this: Dim array(0,0)
One-dimensional arrays look like this: Dim array(0)

Each array can have several elements.

Quote:
>How can I access the two bytes of say an integer indvidually so that I
>can store them in the array.

' Low byte
byte_array(0) = Intg% And &H00FF

' High byte
byte_array(1) = ((Intg% And &HFF00) \ 256) And &H00FF


--
VB 3.0 and Win3.1x assumed

http://www.sn.no/~balchen/
ftp://ftp.sn.no/user/balchen/



Fri, 27 Nov 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Converting integer (or long) data type to array of bytes

2. Need to convert a 16 byte array of bytes to 4 byte integer

3. Byte Array To Long Integer

4. Convert integers and strings to byte array

5. Convert byte-array to integer or real?

6. Copy bytes from an Integer to a location of bytes array

7. Long = Integer * Integer Overflow error

8. Long (integer) vs. Byte

9. 2 bytes to Integer, 4 bytest to Long

10. Efficient method to convert 4 bytes in one Int32 signed integer

11. How to convert bytes to integers ?

12. Need help converting an ip to an integer in host byte order

 

 
Powered by phpBB® Forum Software