Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting large Integers to Bytes

Status
Not open for further replies.

WoundEdGoat

Programmer
May 10, 2002
39
0
0
CA
Can someone tell me how to get an integer value greater then 255 into two byte variables or an array of byte variables? Thanks.
 
Sorry. Didn't explain myself very well again :S

What I need to do is go from and integer to a byte where the integer has a value greater then 255.

EG - Say my intX variable has a value of 999. In hex that would be &H03E7. I need bytX(0) = &H03 and bytX(1) = &HE7.
 
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal dwMemSize As Long)

Function SplitLong(ByVal L As Long, Optional B0 As Byte, Optional B1 As Byte, Optional B2 As Byte, Optional B3 As Byte) As Byte()
Dim B(0 To 3) As Byte
CopyMemory B(0), L, 4
B0 = B(0)
B1 = B(1)
B2 = B(2)
B3 = B(3)
SplitLong = B
End Function

You can retrive the individual bytes in the 4-byte long values by passing optional parameters (B0 to B4) to this function. Or retrieve the 4 bytes as an array as the return value of the function.


Dim B0 As Byte,B1 As Byte, B2 As Byte, B3 As Byte
Dim Bytes() As Byte

Bytes = SplitLong(93874912, B0, B1, B2, B3)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top