Noise can change bits in transit. The data link layer adds redundant bits so that the receiver can detect, and sometimes correct, errors.
Types of Errors
A single-bit error changes one bit. A burst error changes two or more bits in a sequence, and is more common, since noise usually lasts longer than one bit. All error control works by adding redundant bits, computed from the data, which the receiver checks.
Definition: Cyclic redundancy check. An error-detection method in which the sender appends the remainder of a polynomial (modulo-2) division of the data by a generator, so that the received frame divides exactly by the generator if no error occurred.
Error Detection
Parity check: one parity bit is added so that the number of 1s is even (even parity) or odd (odd parity). It detects all single-bit errors and any odd number of errors, but misses an even number. Two-dimensional parity arranges data in rows and columns with a parity bit for each, detecting more errors. Checksum: the data is divided into words (such as 16 bits), which are added using one's-complement arithmetic; the complement of the sum is sent as the checksum, and the receiver adds all the words including the checksum, which should give all 1s (and its complement 0). It is used in IP, TCP and UDP. Cyclic Redundancy Check (CRC): the sender appends r zeros to the data (r = degree of the generator), divides by the generator polynomial using modulo-2 (XOR) division, and replaces the zeros with the remainder. The receiver divides the received frame by the same generator; a zero remainder means no error was detected. CRC detects all burst errors of length up to r and is used in Ethernet (CRC-32).
Error Correction
Errors can be handled by retransmission (ARQ, automatic repeat request) or by forward error correction (FEC), in which enough redundancy is sent for the receiver to fix the error itself. The Hamming code corrects single-bit errors. For m data bits, the number of check bits r must satisfy 2^r ≥ m + r + 1. Check bits are placed at positions that are powers of 2 (1, 2, 4, 8, …). Each check bit covers the positions whose binary number includes it. At the receiver, the check bits are recomputed; the positions of the failing checks add up to give the position of the wrong bit, which is then flipped. The Hamming distance between two codewords is the number of bit positions in which they differ; a code with minimum distance d detects d − 1 errors and corrects (d − 1)/2.
Table 2.2: Error-control methods
| Method | Detects or corrects | Used in |
|---|---|---|
| Parity bit | Detects odd numbers of errors | Serial ports, memory |
| Checksum | Detects most errors | IP, TCP, UDP |
| CRC | Detects bursts up to its degree | Ethernet, Wi-Fi |
| Hamming code | Corrects single-bit errors | ECC memory |
Example 2.2: CRC computation
Problem: Find the CRC for the data 1101011011 with the generator 10011 (x⁴ + x + 1), and the transmitted frame.
Solution:
- The generator has degree 4, so append four 0s: 11010110110000.
- Divide by 10011 using XOR (modulo-2) division.
- The remainder is 1110.
- Replace the four 0s with the remainder: 11010110111110.
Result: CRC = 1110; the frame sent is 11010110111110, which divides exactly by 10011.
def crc_rem(bits, gen):
b = list(bits + "0" * (len(gen) - 1))
for i in range(len(bits)):
if b[i] == "1":
for j in range(len(gen)):
b[i + j] = str(int(b[i + j]) ^ int(gen[j]))
return "".join(b[-(len(gen) - 1):])
data, gen = "1101011011", "10011"
r = crc_rem(data, gen)
frame = data + r
print("CRC remainder:", r, "| frame:", frame)
print("receiver check (should be 0000):", crc_rem(frame, gen))
Output
CRC remainder: 1110 | frame: 11010110111110
receiver check (should be 0000): 0000
Common mistakes
- Using ordinary subtraction instead of XOR in CRC division.
- Thinking that a parity bit detects all errors. It misses even numbers of bit errors.
- Placing Hamming check bits at the wrong positions; they go at 1, 2, 4, 8, ….
Key takeaways
- Errors are single-bit or burst errors.
- Detection: parity, checksum and CRC; CRC uses modulo-2 division.
- Correction: retransmission (ARQ) or FEC such as Hamming codes.
- Hamming check bits r satisfy 2^r ≥ m + r + 1.
Practice questions
- What does a zero CRC remainder at the receiver mean?
- How many check bits does a Hamming code need for 7 data bits?
- Which error-detection method does Ethernet use?
Answers to the practice questions
- No error has been detected.
- 4, since 2^4 = 16 ≥ 7 + 4 + 1.
- CRC-32.
Sources
- Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit II
