CRC is an error-detection code used to detect accidental changes to raw data (e.g., during transmission or storage). It works by treating the data as a polynomial and performing polynomial division with a predefined generator polynomial. The remainder of this division becomes the CRC value.

How CRC is Calculated

  1. Convert data to binary: Treat the data as a sequence of bits.
  2. Append zeros: Add n zeros to the end of the data, where n is the degree of the generator polynomial (e.g., CRC-32 uses a 33-bit polynomial, so append 32 zeros).
  3. Polynomial division: Divide the data + zeros by the generator polynomial using modulo-2 arithmetic (XOR operations).
  4. CRC value: The remainder of this division is the CRC checksum.

Example: CRC-8 for String “Hi”

  1. Data: “Hi” in ASCII is 01001000 01101001.
  2. Generator Polynomial: CRC-8 (e.g., x⁸ + x² + x + 1), represented as 100000111.
  3. Append 8 zeros:
    Data becomes 010010000110100100000000.
  4. Perform division:
    • Divide 010010000110100100000000 by 100000111 using XOR.
    • Remainder: Let’s assume the remainder is 00110110 (hex 0x36).
  5. Final CRC0x36.

Use Cases

  • Error detection in:
    • Network protocols (Ethernet, Wi-Fi).
    • Storage systems (hard drives, ZIP files).
    • Quick checksums for small data transfers.
  • Not secure against intentional tampering.