Dim ch As Byte
Dim crc As Word
Dim bt As Byte
Dim tmp As Byte
Dim polynomial As Word
polynomial = 0x1021
Hseropen 9600
ch = "M"
'-----------------------------------------
'This would be a function
'-----------------------------------------
crc = 0xffff
'Hserout "ch = ", #ch, CrLf
crc = crc Xor ch 'XOR crc with ch -
'hserout "initial XOR = " #crc, CrLf
For bt = 0 To 8
tmp = crc And 1 'if(crc & 1)
'Hserout "tmp = ", #tmp, CrLf
If tmp = 1 Then 'is this right?
crc = ShiftRight(crc, 1) 'shift to the right
'Hserout "After Shift = ", #crc, CrLf
crc = crc Xor polynomial
'Hserout "After XOR = ", #crc, CrLf, CrLf
Else
crc = ShiftRight(crc, 1)
'Hserout "Just Shift crc = ", #crc, CrLf, CrLf
Endif
Next bt
Hserout "CRC = ", #crc, CrLf 'M = 7899
End