Here you are the
VB
function (very
C
-like code: it is a direct porting of the 'ufficial'
C
routine, see [
^]).
If efficiency matters, consider porting a table-based one.
Function calcrc(ByVal data() As Byte, ByVal count As Integer) As Integer
Dim crc As Integer = 0
Dim i, j As Integer
Dim d As Integer
For i = 0 To count - 1
d = data(i)
crc = crc Xor (d << 8)
For j = 0 To 7
If ((crc And &H8000) <> 0) Then
crc = (crc << 1) Xor &H1021
Else
crc = (crc << 1)
End If
Next
Next
calcrc = crc And &HFFFF
End Function
The following code is a test with your first chunk of data:
Sub Main()
Dim data(6) As Byte
Dim crc As Integer
data(0) = &H38
data(1) = &H51
data(2) = &H4D
data(3) = &H4E
data(4) = &H30
data(5) = &H30
data(6) = &H23
crc = calcrc(data, 7)
End Sub
:)