Can a Parity Bit Catch Every Error? Exploring Error Detection with MATLAB
Summary
Learning Goals
- Explain how an even-parity bit is generated.
- Predict which patterns of bit errors a single parity check detects.
- Construct a counterexample to the claim that a passing check guarantees correct data.
- Use a computational experiment to test and explain a prediction.
Context for Use
This activity is intended for introductory computer science or computer networks courses after students encounter binary representation. It accommodates small or large classes using pairs or an instructor-led demonstration.
Students should understand bits and odd/even numbers. MATLAB experience is limited to opening a provided script, changing one variable, and clicking Run. Have the script open before the activity begins; no additional toolboxes are required.
Description and Teaching Materials
Present this question:
A receiver checks a transmitted message and finds no parity error. Can it conclude that the message is unchanged?
Explain that the sender appends one bit so that the entire transmitted word contains an even number of ones. Students then experiment with the supplied MATLAB script.
Time Instructor and student actions
0–1 min Introduce even parity using 10110010. Ask which parity bit should be appended.
1–2 min Students predict whether zero, one, two, and three flipped bits will trigger an error.
2–5 min Pairs run four trials by changing flipPositions to [], [3], [3 5], and [2 3 5]. They record each result.
5–7 min Pairs explain the results and propose a general rule. Discuss why two flips can escape detection.
7–9 min Students individually answer the exit question below; the instructor reviews responses.
The central MATLAB operations are included below.
The downloadable script also plots the sent and received words. MATLAB's array operations make the bit changes explicit, while its plotting functions help students connect the binary data to the detection result. The same experiment could be implemented in another language.
MATLAB Code For Above Teaching Activity (Text File 324bytes Sep30 26)
Teaching Notes and Tips
Expected results:
Flipped positions Number of flipped bits Receiver result
[] 0 No error detected
[3] 1 Error detected
[3 5] 2 No error detected
[2 3 5] 3 Error detected
Each flipped bit changes the parity of the total number of ones. Therefore, the check detects any odd number of flipped bits and misses any positive even number, including errors affecting the parity bit.
Emphasize these distinctions:
- "No error detected" does not mean "no error occurred."
- The receiver uses only the received word; it does not possess the original data for comparison.
- This single parity check cannot locate or correct an error.
- Students must rerun the whole script for each trial and list each flipped position only once.
Assessment
Exit question:
Four distinct bits change during transmission, and the parity check passes. Does this prove that the received data are correct? Explain.
Expected answer: No. Four flips preserve even parity, so the data can change without triggering the check.
Award one point for rejecting the guarantee and one point for explaining why an even number of flips is undetected.
References and Resources
The relevant MATLAB references are sum (https://www.mathworks.com/help/matlab/ref/double.sum.html), mod(https://www.mathworks.com/help/matlab/ref/double.mod.html), and stem(https://www.mathworks.com/help/matlab/ref/stem.html).
The parity logic was independently verified for all 512 possible error patterns in the nine-bit word. The script has not been executed in MATLAB, so run it once before class. For submission, select Work in progress until that check is complete. SERC's activity collection was inaccessible during review, so similarity to existing submissions remains unchecked.