Converting integer (or long) data type to array of bytes 
Author Message
 Converting integer (or long) data type to array of bytes

Hi,
I would like to convert integer or long variable to array of bytes.
I'm using VB.NET environment.
Maybe you know some easy way to do this.

Marcin



Sat, 09 Apr 2005 19:23:00 GMT  
 Converting integer (or long) data type to array of bytes
Have you tried the binary object built into .net yet?



Quote:
> Hi,
> I would like to convert integer or long variable to array of bytes.
> I'm using VB.NET environment.
> Maybe you know some easy way to do this.

> Marcin



Sun, 10 Apr 2005 00:28:48 GMT  
 Converting integer (or long) data type to array of bytes
This is a copy I stole :) Hope this is what you need.

----------------------------------------------------<quote>


Onderwerp:Re: integer to bytes

View this article only
Discussies:comp.lang.basic.visual
Datum:2002-09-05 01:32:11 PST

Give this code a try (it loads a ByteArray with your values). Put a
CommandButton on your Form and paste this code into the Form's code
window.

Rick

Private Declare Sub CopyMemory _
        Lib "kernel32" _
        Alias "RtlMoveMemory" _
       (pDst As Any, _
        pSrc As Any, _
        ByVal ByteLen As Long)

Private Sub Command1_Click()
  Dim DoubleValue As Double
  Dim ByteArray(7) As Byte
  DoubleValue = 0.334415314190595
  CopyMemory ByteArray(0), _
             DoubleValue, _
             Len(DoubleValue)
  ' Let's see what we got
  For x = 0 To 7
    Debug.Print ByteArray(x), Chr$(ByteArray(x))
  Next
End Sub

----------------------------------------------------<end quote>



Sun, 10 Apr 2005 05:04:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Converting integers and long integers to byte arrays

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. Byte, Int16, and Integer Data Types?

7. Data Type Efficiency - Byte vs. Integer

8. Converting from a Long to an Array of Bytes

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

10. Convert user defined type or variant to byte array (and back)

11. Convert array of value type to array of reference type

12. Long (integer) vs. Byte

 

 
Powered by phpBB® Forum Software