Created
December 4, 2015 22:43
-
-
Save freretuc/2502f564d0b9f3b14bdd to your computer and use it in GitHub Desktop.
CRC16 function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use as
Dim a(2) As Byte
a(0) = &HCA
a(1) = &H0
a(2) = &HF7
CRC(a, 3, &HA001, &HFFFF)