Skip to content

Instantly share code, notes, and snippets.

@freretuc
Created December 4, 2015 22:43
Show Gist options
  • Save freretuc/2502f564d0b9f3b14bdd to your computer and use it in GitHub Desktop.
Save freretuc/2502f564d0b9f3b14bdd to your computer and use it in GitHub Desktop.
CRC16 function
Function CRC(ByVal bData() As Byte, ByVal iLength As Integer, ByVal iPolynome As Integer, ByVal iCRC As Integer)
Dim flag As Boolean
For i As Integer = 0 To iLength - 1
iCRC = iCRC Xor bData(i)
For j = 0 To 7
If (iCRC And &H1) = 1 Then flag = True Else flag = False
iCRC = iCRC \ 2
If flag Then iCRC = iCRC Xor iPolynome
Next
Next
Return Hex(iCRC And &HFFFF)
End Function
@freretuc
Copy link
Author

freretuc commented Dec 4, 2015

Use as
Dim a(2) As Byte
a(0) = &HCA
a(1) = &H0
a(2) = &HF7
CRC(a, 3, &HA001, &HFFFF)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment