1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| '-------------------------------------------------
Public Function ModCRC(Buffer() As Variant) As Long
'-------------------------------------------------
Dim CRC1 As Variant
Dim J As Integer
Dim K As Long
Dim c As Long
Dim l As Long
Application.Volatile
CRC1 = &HFFFF ' init CRC
For l = 1 To UBound(Buffer) ' pour chaque mot (2 octets par mot)
c = 1 ' init index colonne
While c < 3
CRC1 = CRC1 Xor Buffer(l, c)
For J = 0 To 7 ' pour chaque bit dans l'octet
K = CRC1 And 1 ' memorisation du bit de poid faible
CRC1 = ((CRC1 And &HFFFE) / 2) And &H7FFF ' decalage à droite apres masquage du bit de poid faible
If K > 0 Then CRC1 = CRC1 Xor &HA001
Next J ' bit suivant
c = c + 1
Wend
Next l ' mot suivant
ModCRC = CRC1
End Function |
Partager