Sub topic 1
Why frames get corrupted: single-bit and burst errors
Prerequisites
This chapter assumes you know:
- Binary numbers and bitwise XOR, where 1 XOR 1 = 0 and 1 XOR 0 = 1.
- The data link layer, which moves frames between directly connected nodes.
- The difference between bandwidth and propagation delay.
Single-bit and burst errors
Noise on a wire, radio link, or fiber can flip bits. A single-bit error changes one bit in a frame. A burst error changes a run of consecutive bits, measured from the first corrupted bit to the last. Burst errors are more common on real links, so a detection scheme must handle them.
Every scheme adds redundant bits, which the receiver checks. The receiver rejects a frame when the check fails.
Parity and two-dimensional parity
A parity bit makes the count of 1s even (even parity) or odd (odd parity). One parity bit detects any odd number of flipped bits, but misses two flips. Two-dimensional parity arranges data in rows and columns and adds a parity bit to each row and column. It can locate a single error at the intersection of a bad row and a bad column.
Hamming distance and Hamming code
The Hamming distance between two codewords is the number of bit positions where they differ. A code with minimum distance d detects up to d - 1 errors and corrects up to (d - 1) / 2 errors. The code {000, 111} has distance 3, so it detects 2 errors and corrects 1. A Hamming code places check bits at power-of-two positions, so the pattern of failed checks points to the bit that flipped.
The Internet checksum
The Internet checksum adds the data as 16-bit words in ones' complement arithmetic, then stores the complement of the sum. It is cheap to compute but misses some errors, such as swapped words.
CRC: generator polynomials and modulo-2 division
A cyclic redundancy check (CRC) divides the data, with zeros appended, by a generator polynomial using modulo-2 division, which is XOR without carries. The remainder is the check value. The following code reproduces the standard example.
def crc_remainder(data: str, generator: str) -> str:
n = len(generator) - 1
bits = [int(b) for b in data + "0" * n]
gen = [int(b) for b in generator]
for i in range(len(data)):
if bits[i]:
for j in range(len(gen)):
bits[i + j] ^= gen[j]
return "".join(str(b) for b in bits[-n:])
print(crc_remainder("1101011111", "10011")) # 0010CRC detects all burst errors shorter than the generator's degree plus one.
Sharing one channel: static versus dynamic allocation
Static allocation, such as frequency division, gives each station a fixed slice of the channel. It wastes capacity when a station is idle. Dynamic allocation lets stations compete for the channel when they have data, which leads to the medium access protocols in later chapters.
Exercise
A 7-bit data word 1011001 has four 1s. Which even-parity bit must be appended?
Show answer
0, because the count of 1s is already even.
Exercise
A code has minimum Hamming distance 3. How many errors can it detect, and how many can it correct?
Show answer
It detects 2 errors and corrects 1 error, since (3 - 1) / 2 = 1.