Friday, April 20, 2012

Exercise 4 CRC-16 calculation

Mask represents the generator polynomial
(A001 == x^16 + x^15 + x^2 + 1 where x^16 is gone and LSB represents x^15).

Data bits are fed from LSB to MSB
At each iteration CRC is shifted to the right one bit
If data bit and LSB in CRC do not match, then crc ^= mask

So for data = 0x41
initial crc = 0x0000
first bit = 1
does not match crc's LSB so shift + xor
crc=0xa001
second bit = 0
does not match crc's LSB so shift + xor
crc=0xf001
third bit = 0
does not match crc's LSB so shift + xor
crc=0xd801
fourth bit = 0
does not match crc's LSB so shift + xor
crc=0xcc01
fifth bit = 0
does not match crc's LSB so shift + xor
crc=0xc601
sixth bit = 0
does not match crc's LSB so shift + xor
crc=0xc301
seventh bit = 1
shift only
crc=0x6180
eighth bit = 0
shift only
crc=0x30c0

4 comments:

  1. Are you using a table-based algorithm?

    ReplyDelete
  2. No, I am not, it is a shift register as the one shown in the picture.

    ReplyDelete
  3. Please note that as it is mentioned in this document CRC-16 requires the bit reversal of the resulting remainder.

    ReplyDelete