CRC Implementation in C

CRC Implementation in C with efficient algorithm. CRC Implementation with bitwise operators and example.

Best error detection algorithm which used for data transmission.



Modulo-2 binary division

CRC Modulo 2 Division

CRC Modulo 2 Division


The modulo-2 division process is defined as follows:

Call the uppermost c+1 bits of the message the remainder

  • Beginning with the most significant bit in the original message and for each bit position that follows, look at the c+1 bit remainder:
    • If the most significant bit of the remainder is a one, the divisor is said to divide into it. If that happens (just as in any other long division) it is necessary to indicate a successful division in the appropriate bit position in the quotient and to compute the new remainder. In the case of modulo-2 binary division, we simply:
      • Set the appropriate bit in the quotient to a one, and
      • XOR the remainder with the divisor and store the result back into the remainder
    • Otherwise (if the first bit is not a one):
      • Set the appropriate bit in the quotient to a zero, and
      • XOR the remainder with zero (no effect)
    • Left-shift the remainder, shifting in the next bit of the message. The bit that’s shifted out will always be a zero, so no information is lost.

The final value of the remainder is the CRC of the given message.

CRC Implementation in C

Common file for Both and Reciever

 CRC Sender Code

CRC Receiver Code