Error Detection

Detecting corrupted data. Learn parity bits, checksums (Internet checksum), cyclic redundancy checks (polynomial division, generator polynomials, burst-error detection, CRC-16/32), undetected error probability, and ARQ retransmission (stop-and-wait, go-back-N, selective repeat).

Every Ethernet frame, USB packet, CAN message and ZIP file carries a CRC. Detecting errors (and asking for retransmission) is often simpler and more efficient than correcting them.

An analogy

A checksum is like counting the items in a parcel and writing the total on the label: if the count at arrival differs, something was lost or changed.

Parity

One extra bit makes the number of 1s even (or odd). Detects any single-bit error but misses two-bit errors. Used in UART frames and memory.

Checksums

Sum of data words (e.g. 16-bit one's-complement Internet checksum in IP/UDP/TCP). Cheap in software, weaker than CRC against certain error patterns.

CRC

Treat data as a polynomial and divide by a generator using XOR. An r-bit CRC detects all single and double errors (for good polynomials), all odd numbers of errors (if (x + 1) is a factor), and all bursts ≤ r bits.

ARQ

Detected errors trigger retransmission: stop-and-wait (simple, inefficient on long links), go-back-N and selective repeat (sliding windows). Hybrid ARQ (LTE/5G) combines FEC with retransmissions and soft combining.

Formulas

Worked example: Parity

Given: Data 1011001 (four 1s); Even parity

Find: Parity bit.

Answer: Transmit 1011001 0

Worked example: CRC strength

Given: CRC-32

Find: Undetected probability for random corruption.

Answer: ≈ 1 in 4.3 billion corrupted frames

CRC-16/CCITT-FALSE in C

#include <stdint.h>
#include <stddef.h>

/* Polynomial x^16 + x^12 + x^5 + 1 (0x1021), init 0xFFFF */
uint16_t crc16_ccitt(const uint8_t *data, size_t len) {
    uint16_t crc = 0xFFFF;
    while (len--) {
        crc ^= (uint16_t)(*data++) << 8;
        for (int i = 0; i < 8; i++)
            crc = (crc & 0x8000) ? (uint16_t)((crc << 1) ^ 0x1021) : (uint16_t)(crc << 1);
    }
    return crc;
}
/* crc16_ccitt("123456789", 9) == 0x29B1  (standard check value) */

The bitwise loop implements mod-2 polynomial division. Production code uses a 256-entry lookup table or hardware CRC units found in most MCUs. The check value verifies an implementation.

Common mistakes

Applications

Key takeaways

Going further