'This example is ment to be correct: 0F 03 08 13 24 13 88 13 5B 00 01 = CRC16: 0x0FD2
DataCRC$(0) = "0F"
DataCRC$(1) = "03"
DataCRC$(2) = "08"
DataCRC$(3) = "13"
DataCRC$(4) = "24"
DataCRC$(5) = "13"
DataCRC$(6) = "88"
DataCRC$(7) = "13"
DataCRC$(8) = "5B"
DataCRC$(9) = "00"
DataCRC$(10) = "01"
[start]
PRINT "MODBUS CRC-16 calculator"
PRINT "ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ"
[calculate]
CRCRegister = 65535 '&hFFFF
FOR X = 0 to 10
CRCRegister = CRCRegister XOR HEXDEC(DataCRC$(0))
FOR Z = 0 TO 7
IF (CRCRegister MOD 2) = 1 THEN 'chek if the LSB is a "1"
CRCRegister = INT(CRCRegister / 2) 'shift CRCRegister one bit to the right
CRCRegister = CRCRegister XOR 40961 '&hA001
ELSE
CRCRegister = INT(CRCRegister / 2) 'shift CRCRegister one bit to the right
END IF
NEXT Z
NEXT X
PRINT "CRC16 (0x0FD2) : "; CRCRegister, DECHEX$(CRCRegister)
END