1,066
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Function CRC_16(aBuff() As Byte, ByVal lenth As Long) As Integer
Dim k As Long
Dim temp As Long
Dim p As Long
temp = 0
p = LBound(aBuff)
Do While (lenth > 0)
lenth = lenth - 1
k = 128
Do
If (k = 0) Then Exit Do
temp = temp + temp
If ((temp And &H10000) <> 0) Then temp = temp Xor &H18005
If ((aBuff(p) And k) <> 0) Then temp = temp Xor &H8005&
k = k \ 2
Loop
p = 1& + p
Loop
If ((temp And &H8000) = 0) Then
temp = temp And &H7FFF&
Else
temp = temp Or &HFFFF8000
End If
CRC_16 = temp
End Function
Private Sub Command1_Click()
Dim arrTest() As Byte
'55 13 85 67 AD 65 CRC校验后 :B3DC
ReDim arrTest(5)
arrTest(0) = &H55
arrTest(1) = &H13
arrTest(2) = &H85
arrTest(3) = &H67
arrTest(4) = &HAD
arrTest(5) = &H65
MsgBox Hex$(CRC_16(arrTest, 6)), 64
End Sub