0
votes

Let us get an m bit-message where the last n bits are the CRC bits. As far as I know, in order to check if it is received correctly or not, we should XOR all m bits with the polynomial of the specific CRC algorithm. If the result is all-zeros, we can say there are no errors.

Here are my questions:

1) What about calculating the n CRC bits using the first (m-n) bits and then compare it to the last n bits of the received message? This way we can say there are no errors if the received and calculated n bits are equal. Is this approach true?

2) If it is true, which is more efficient?

1
m is usually orders of magnitude larger than n so the saving is vanishingly small. It's preferable to use the first technique as it is also a sanity-check on your code.user207421
May I ask how this sanity-check works? And I understand from your comment and the other answer that "XOR & get all-zeros" method is pereferable for some of the CRC types only since some algorithms do not give all-zeros.groove

1 Answers

3
votes

Your description of how to check a CRC doesn't really parse. But anyway, yes, the way that a CRC check is normally done is to calculate the CRC of the pre-CRC bits, and then to compare that to the CRC sent. It is very marginally more efficient that way. More importantly, it is more easily verifiable to be correct, since that is the way the CRC is generated and appended on the other end.

That method extends to any style of check value, where other check values do not have the mathematical property of getting zero if you run the CRC through the algorithm after the data that precedes it. Also CRCs with pre- and post-conditioning, which is most of them, won't have that property either. You would need to un-post-condition, and then compare the result with the pre-condition value.