Edexcel International Advanced Level Computer Science, point 12.3.3
Definition
Error detection is adding extra information to data so that the receiver can tell whether it was damaged (bits flipped) during transmission or storage. It detects errors: it doesn't always correct them. If an error is found, the receiver asks for the data to be sent again.
Function and why needed
Signals are affected by interference and noise, so bits can change from 0 to 1 or the reverse in transit. Without checks, corrupted data could be accepted as correct (integrity, 12.3.1). Error detection is used in networks (the packet trailer, 12.1.3), storage, and memory.
a. Parity bit
How it works
A parity bit is one extra bit added to each group of bits, chosen so that the total number of 1s is always even (even parity) or always odd (odd parity). The sender and receiver agree which.
Even parity: the parity bit makes the number of 1s even.
| Data (7 bits) | Number of 1s | Parity bit | Transmitted (8 bits) |
|---|---|---|---|
1011001 |
4 (even) | 0 | 10110010 |
1011011 |
5 (odd) | 1 | 10110111 |
0000000 |
0 (even) | 0 | 00000000 |
Checking
The receiver counts the 1s in the whole received byte. If the count is even (for even parity), the byte is accepted. If it's odd, there's an error.
| Received | Number of 1s | Result |
|---|---|---|
10110010 |
4 (even) | OK |
10110110 |
5 (odd) | Error detected (one bit flipped) |
10100110 |
4 (even) | Not detected! (two bits flipped) |
Strengths and weaknesses
- Benefits: very simple and fast, only 1 extra bit per group (low overhead), and detects any single-bit error (and any odd number of bit errors).
- Drawbacks: misses an even number of errors (two flipped bits cancel out), can't tell which bit is wrong, so it can't correct, and gives no help with burst errors that affect several bits.
b. Two-dimensional parity block
How it works
Data is arranged in a block (rows and columns), with a parity bit for each row and each column. This can locate a single-bit error, so that it can be corrected.
Example (even parity): three rows of four data bits.
| c0 | c1 | c2 | c3 | Row parity | |
|---|---|---|---|---|---|
| r0 | 1 | 0 | 1 | 1 | 1 (three 1s, so add 1) |
| r1 | 0 | 1 | 1 | 0 | 0 (two 1s) |
| r2 | 1 | 1 | 0 | 0 | 0 (two 1s) |
| Column parity | 0 | 0 | 0 | 1 | 1 (corner) |
- Column parities: c0 has two 1s (0), c1 has two (0), c2 has two (0), c3 has one (1).
- The corner bit is the parity of the parity bits (here 1, from either the row bits 1, 0, 0 or the column bits 0, 0, 0, 1).
Finding and correcting an error
Suppose the bit at r1, c2 flips (1 to 0) in transit. The receiver recalculates:
| c0 | c1 | c2 | c3 | Row parity check | |
|---|---|---|---|---|---|
| r0 | 1 | 0 | 1 | 1 | OK |
| r1 | 0 | 1 | 0 | 0 | FAIL (one 1 but the parity bit is 0) |
| r2 | 1 | 1 | 0 | 0 | OK |
| Column check | OK | OK | FAIL | OK |
Row r1 fails and column c2 fails, so the error is at their intersection (r1, c2). The receiver flips that bit back to 1: the data is corrected.
- Benefits: locates and corrects single-bit errors, and detects more error patterns than a simple parity bit.
- Drawbacks: more overhead (extra bits for every row and column), can't correct two or more errors in a block (it can detect some), and still misses some patterns (four errors at the corners of a rectangle).
c. Checksum
How it works
A checksum is a value calculated from a block of data by a mathematical rule, and sent with it. The receiver calculates it again and compares. A mismatch means an error.
A simple checksum: add up all the data bytes, then keep the remainder after dividing by 256 (the sum modulo 256, which fits in one byte).
Example: the data "Hello" is the bytes 72, 101, 108, 108, 111 (2.3.1).
- Sum .
- Checksum (binary
11110100). - Send the data and 244.
The receiver adds the received data bytes again and compares with 244.
| Received data | Sum mod 256 | Result |
|---|---|---|
| 72, 101, 108, 108, 111 | 244 | Match: OK |
| 72, 101, 109, 108, 111 | 245 | Mismatch: error detected |
| 72, 101, 109, 108, 110 | 244 | Not detected! (two changes cancel out) |
Variants: the Internet checksum (used in IP, TCP and UDP) uses 16-bit one's complement addition, a CRC (cyclic redundancy check) uses polynomial division and detects burst errors much better, and hash functions such as SHA-256 (for file integrity and downloads).
Strengths and weaknesses
- Benefits: checks a whole block with one small value, simple and fast, and good at catching random errors.
- Drawbacks: errors that cancel out aren't detected (a swap of two bytes gives the same sum), it can't correct errors, and it isn't secure against deliberate tampering: an attacker can change the data and recalculate the checksum.
Comparing the methods
| Parity bit | 2D parity block | Checksum | |
|---|---|---|---|
| Overhead | 1 bit per group | Row and column bits | A byte or more per block |
| Detects single-bit error | Yes | Yes | Yes |
| Corrects errors | No | Yes (single-bit) | No |
| Misses | Even numbers of errors | Some multiple-error patterns | Errors that cancel out |
| Typical use | Memory, serial links | Storage, simple communication | Network packets, file transfers |
What happens when an error is found?
- The receiver asks for the data to be sent again (automatic repeat request (ARQ), as TCP does with acknowledgements, 12.1.2).
- Forward error correction (such as Hamming codes) adds enough extra data to fix errors without a resend, useful where resending isn't practical (space communications).
Worked example
Task: the 7-bit value 1101010 is sent with an even parity bit. Work out the transmitted byte, and decide whether each received byte is accepted.
Transmitted byte: 1101010 has four 1s (even), so the parity bit is 0: 11010100.
| Received | Number of 1s | Accepted? | Comment |
|---|---|---|---|
11010100 |
4 | Yes | Correct |
11010101 |
5 | No | One bit flipped: error detected |
11010110 |
5 | No | One bit flipped: error detected |
11110110 |
6 | Yes (wrongly) | Two bits flipped: the count is still even, so the error is missed |
Conclusion: a single parity bit detects one flipped bit but can't detect two. A checksum or a 2D parity block is more reliable.
Exam tip: be able to calculate a parity bit (count the 1s, and add a bit to make the total even), fill in a 2D parity block, find the error from the failing row and column, and calculate a checksum (sum, then the rule given). State what each method can and can't do (detect or correct, limits).
Check yourself
What even parity bit would be added to 1001011?
0 (1001011 has four 1s, which is already even).
What type of error can a single parity bit not detect?
An even number of bit errors, such as two flipped bits, because the count of 1s stays even.
How does a two-dimensional parity block locate an error?
The failing row parity and failing column parity intersect at the position of the flipped bit.
What is the checksum (sum mod 256) of the bytes 120, 90 and 70?
280 mod 256 = 24.
What happens when a receiver detects an error?
It rejects the data and requests it to be sent again.