Implement CRC algorithm from equation
I am dealing with a device that says to use this 16-bit cyclic redundancy check:
CCITT CRC-16 with polynomial x^16 + x^12 + x^5 + x^1
I was looking for an implementation of such an algorithm, but I only found those in which the last term of the equation is 1
(i.e. x^0
) instead of x^1
, for example, this or this .
I was about to implement the algorithm myself when I realized I didn't know where to start. How is CRC calculation supposed to start with an equation?
source to share
This PDF file explains the topic: hackersdelight.org/crc.pdf .
I also recommend Andrew Tanenbaum's computer networking as it has a chapter on CRC algorithm.
Finally, I would double check that your device actually implements this form of CRC and not the standard one. It could be a typo.
source to share
You are right and the polynomial is wrong. A regular CRC polynomial must always have 1 member. The CCITT CRC-16 polynomial is x ^ 16 + x ^ 12 + x ^ 5 + 1 as @guga noted, or 0x1021 in bit form (which leaves x ^ 16). See the 16-bit CRC catalog .
This information also contains other key information that you need besides the polynomial. In particular:
width=16 poly=0x1021 init=0x1d0f refin=false refout=false xorout=0x0000 check=0xe5cc
which means the CRC is not reflected in bits, it is initialized with 0x1d0f
and the result is no exception due to anything. So CRIT CCITT without bytes 0x1d0f
. It also provides a check value for the ASCII-digit devyatibaytovoy string "123456789" 0xe5cc
. You should use this to test your implementation.
Ross Williams' Guide will tell you everything you need to know about CRC implementation.
source to share