VB 长整型和字节数组的转换问题 (LongByte) | 雨律在线

用到的API声明:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Long2Byte

Dim TempLng As Long
Dim
TempBytes(0 To 3) As Byte

TempLng = 2000

#If 方法1 Then
CopyMemory TempBytes(0), TempLng, 4
#ElseIf 方法2 Then
TempBytes(0) = TempLng And &HFF
TempBytes(1) = (TempLng And &HFF00&) \ &H100
TempBytes(2) = (TempLng And &HFF0000) \ &H10000
TempBytes(3) = (TempLng And &H7F000000) \ &H1000000 Or (((TempLng And &H80000000) <> 0) And &H80)
#End If


Byte2Long

Dim l_byte(0 To 3) As Byte '要被转化的Byte()
Dim l_long As Long '要保存转化的Long
l_byte(0) = &1F
l_byte(1) = &2F
l_byte(2) = &3F
l_byte(3) = &4F
l_long = "&H" & (CStr(Hex(l_byte(0))) & CStr(Hex(l_byte(1)))) & CStr(Hex(l_byte(2))) & CStr(Hex(l_byte(3)))


 
目前有0条回应
Comment
Trackback
你目前的身份是游客,请输入昵称和电邮!