Sub calcCRC( data() As Byte, num As Int) As Int
Dim crc As Int=0
For k=0 To num-1
crc = Bit.Xor( crc, Bit.ShiftLeft( data(k),8) )
For i=0 To 7
crc = Bit.ShiftLeft(crc,1)
If Bit.And(crc,0x10000)<>0 Then
crc = Bit.Xor(crc,0x1021)
End If
Next
Next
crc = Bit.And(crc,0xFFFF) 'need to clean since the container was bigger
Return crc
End Sub