发表于:2008-11-11 13:56:34
楼主
unction CalCRC(BCRC As Integer, GP As Long, BDF As Long) As Long
Dim C1&, C2&
Dim A1%, preC1&
Dim LeftValue%, A1Shift%
If BDF = 0 Then
CalCRC = 0
Exit Function
End If
A1 = (Len(Hex(BDF)) - 1) * 4
C1 = BDF * 2 ^ BCRC
LeftValue = Val("&H" &mid(Hex(BDF), 1, 1))
If LeftValue >= 1 Then A1Shift = 1
If LeftValue >= 2 Then A1Shift = 2
If LeftValue >= 3 Then A1Shift = 3
If LeftValue >= 4 Then A1Shift = 4
A1 = A1 + (A1Shift - 1)
C2 = GP * 2 ^ A1
Do
preC1 = C1
C1 = C1 Xor C2
Do
A1 = A1 - 1
If C1 > preC1 Then
C1 = preC1 Xor (GP * 2 ^ A1)
Else
Exit Do
End If
Loop
C2 = GP * 2 ^ A1
Loop Until C1 <= GP
CalCRC = C1
End Function