我在VB6中将字节数组转换为有符号整数时遇到了问题。在.NET中使用BitConverter很容易实现,但我不确定在VB6中该怎么做。 谢谢。
很遗憾,没有内置的功能,您需要自己编写一个。以下是一个快速示例,可帮助您入门。
Private Function BArrayToInt(ByRef bArray() As Byte) As Integer
Dim iReturn As Integer
Dim i As Integer
For i = 0 To UBound(bArray) - LBound(bArray)
iReturn = iReturn + bArray(i) * 2 ^ i
Next i
BArrayToInt = iReturn
End Function
空气代码(可能会导致您的电脑崩溃,引发恐龙攻击等)。
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, _ source As Any, ByVal bytes As Long)
Dim a() As Byte
Dim n As Integer
'get the bytes somehow into a()
CopyMemory n, a(0), 2