andrey
andrey

Reputation: 1595

How to detect errors in CRC-protected data?

As far as I understand to check if the data with it's CRC appended to the end of it has errors, one needs to run it through the same CRC algorithm and see if the newly calculated CRC is zero.

I've tried going though this using an online CRC calculator in the following way:

  1. Calculate CRC for 0xAABBDD (without the 0x part) - CRC16 outputs 0x8992
  2. Calculate CRC for 0xAABBDD8992 - CRC16 outputs 0xFB4A, not 0x0000

What am I doing wrong?

Upvotes: 0

Views: 136

Answers (1)

Mark Adler
Mark Adler

Reputation: 112404

The appending the CRC thing only works for "pure" CRCs without pre and post-conditioning. Most real world CRCs however have pre and post-conditioning, mainly so that the CRC of strings of zeros are not zero.

The way to check a CRC is the same as any other check value. You get a message m c where m are the message bytes and c is the check value. You are told through some other channel (most likely a standards document) that c=f(m), with some description of the function f. To check the integrity of m c, you compute f(m) and see if that is equal to c. If not, then the message and/or check value were corrupted in transit. If they are equal, then you have some degree of assurance that the message has arrived unscathed. The assurance depends on the nature of f, the number of bits in c, and the characteristics of the possible errors on the transmission channel.

Upvotes: 1

Related Questions