本帖最后由 yst803 于 2011-10-04 21:31:18 编辑

解决方案 »

  1.   

    完全可以直译:Function crc5_epc(ptr() As Byte, bylen As Byte) As Byte
        Dim i As Byte
        Dim j As Byte
        Dim k As Byte
        Dim crc As Byte
        crc = &H9
        j = &H80
        k = 0
        For i = 0 To bylen - 1
            If crc And &H10 Then
                crc = crc * 2
                crc = crc Xor &H9
            Else
                crc = crc * 2
            End If
            If ptr(i) And j Then crc = crc Xor &H9
            j = Int(j / 2)
            k = k + 1
            If k = 8 Then
                j = &H80
                k = 0
            End If
        Next i
        crc5_epc = crc And &H1F
    End Function
      

  2.   

    Function crc5_epc(ptr() As Byte, bylen As Byte) As Byte我觉得这个变成:
    Function crc5_epc(ptr() As integer, bylen As integer) As integer
    更合理,因为C的原型是无符号的,而VB中的Byte是-128~127的,若换成Integer就符合范围了。
      

  3.   

    晕了,,记错了。。Byte在VB中是无符号的呵呵