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
- Convert data to binary: Treat the data as a sequence of bits.
- Append zeros: Add
n
zeros to the end of the data, wheren
is the degree of the generator polynomial (e.g., CRC-32 uses a 33-bit polynomial, so append 32 zeros). - Polynomial division: Divide the data + zeros by the generator polynomial using modulo-2 arithmetic (XOR operations).
- CRC value: The remainder of this division is the CRC checksum.
Example: CRC-8 for String “Hi”
- Data: “Hi” in ASCII is
01001000 01101001
. - Generator Polynomial: CRC-8 (e.g.,
x⁸ + x² + x + 1
), represented as100000111
. - Append 8 zeros:
Data becomes010010000110100100000000
. - Perform division:
- Divide
010010000110100100000000
by100000111
using XOR. - Remainder: Let’s assume the remainder is
00110110
(hex0x36
).
- Divide
- Final CRC:
0x36
.
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.