3

我无法在 VB6 中从字节数组转换为有符号整数。这在.NET 中使用 BitConverter 很简单,但我不确定如何使用 VB6。谢谢

4

2 回答 2

2

不幸的是没有内置函数,你需要写一个。这是一个快速示例,可帮助您入门。

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
于 2012-11-09T20:58:19.900 回答
1

复制内存

空气代码(可能会使您的 PC 崩溃,导致恐龙攻击等)。

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 
于 2012-11-09T22:39:17.850 回答