← Error Detection (Parity Magic Trick)
Grades 6–8 reading level
Error Detection (Parity Magic Trick)
Adapted with AI from the original open resource by CS Unplugged. Nothing is invented — only the reading level changes.
Activity 4: Card Flip Magic — Finding and Fixing Errors
Summary
When information is stored on a disk or sent from one computer to another, we usually expect it to arrive exactly the way it was sent. But sometimes things go wrong, and the data gets changed by accident. This activity uses a magic trick to show how we can figure out when data has been damaged (called "corrupted") — and even fix it.
Curriculum Links
- Mathematics: Number, Level 3 and up. Exploring computation and estimation.
- Algebra: Level 3 and up. Exploring patterns and relationships.
Skills
- Counting
- Recognizing odd and even numbers
Ages
9 years and up
Materials
- A set of 36 "fridge magnet" cards, colored on one side only
- A metal board (a whiteboard works well) for demonstrating
- Each pair of students will need 36 identical cards, colored on one side only
The "Magic Trick" Demonstration
Here's your chance to be a magician!
You'll need a pile of identical, two-sided cards. (You can make your own by cutting up a large sheet of card that's colored on only one side.) For the demonstration, it's easiest to use flat magnetic cards with a different color on each side — fridge magnets work great.
1. Choose a student to lay out the cards in a 5×5 square, with a random mix of colored and blank sides showing.
Then casually add one more row and one more column, "just to make it a bit harder."
These extra cards are actually the secret to the trick! You must choose them carefully so that every row and every column ends up with an even number of colored cards.
2. Have a student flip over just one card while you cover your eyes. Now the row and column containing that flipped card will have an odd number of colored cards instead of even — and that's how you can spot exactly which card was changed!
Can the students figure out how the trick works?
Teach the Trick to the Students
1. Working in pairs, students lay out their cards in a 5×5 grid.
2. Ask: How many colored cards are in each row and column? Is that number odd or even? (Remember, 0 counts as an even number.)
3. Now add a sixth card to each row, choosing colored or blank so that the total number of colored cards in that row is always even. This extra card is called a parity card — it acts like a built-in check to make sure everything adds up correctly.
4. Add a sixth row along the bottom the same way, so each column also has an even number of colored cards.
5. Now flip one card. What happens to its row and column? (They now have an odd number of colored cards!) Parity cards work like an alarm system — they let you know right away when something has been changed.
6. Take turns performing the trick for each other.
Extension Activities
1. Try using other objects that have two "states" (two possible sides or values). For example, playing cards, coins (heads or tails), or cards printed with 0 or 1 — which connects to how computers use binary (a number system with only two digits, 0 and 1).
2. What happens if you flip two or more cards? It's not always possible to know exactly which two were changed, but you can tell that something is wrong. Usually you can narrow it down to one of two possible pairs. If four cards are flipped, it's even possible that all the parity cards look correct afterward — meaning the error could go completely unnoticed!
3. Look at the card in the bottom right corner. If you choose its color to make the column above it correct, will it also be correct for the row to its left? (Yes — always!)
4. In this activity, we used even parity, meaning every row and column has an even number of colored cards. Could we use odd parity instead, where every row and column has an odd number? Yes, this works too — but the bottom-right card will only satisfy both its row and its column if the number of rows and the number of columns are both even or both odd. For example, a 5×9 grid or a 4×6 grid would work, but a 3×4 grid would not.
A Real-Life Example for Experts!
This same checking method is used with book codes. Published books have a ten-digit code, usually printed on the back cover, called an ISBN (International Standard Book Number). The tenth digit is a special check digit — it works just like the parity cards in our activity.
This means that when you order a book using its ISBN, the publisher can check whether you typed it correctly, just by looking at this check digit. That way, you won't accidentally end up with the wrong book!
Here's how to calculate the check digit:
Multiply the first digit by 10, the second digit by 9, the third by 8, and so on, all the way down to the ninth digit multiplied by 2. Then add up all these results.
For example, for the ISBN 0-13-911991-4:
(0×10) + (1×9) + (3×8) + (9×7) + (1×6) + (1×5) + (9×4) + (9×3) + (1×2) = 172
Next, divide this total by 11 and find the remainder:
172 ÷ 11 = 15, remainder 7
If the remainder is 0, the check digit is 0. Otherwise, subtract the remainder from 11:
11 – 7 = 4
Now check: is this the same as the last digit of the ISBN? Yes, it matches! If the last digit hadn't been 4, we'd know a mistake had been made somewhere in the code.
Sometimes this calculation gives a result of 10, which can't fit in a single digit — in that case, the letter X is used instead.
A barcode (UPC) from a box of Weet-Bix™ cereal is another example.
Grocery store barcodes (called UPC codes) use a similar idea, though the formula is different. If a barcode is scanned incorrectly, the final digit won't match what it should be. When that happens, the scanner beeps, and the checkout worker scans the item again.
Check That Book!
Detective Blockbuster Book Tracking Service, Inc.
We find and check ISBN check digits for a small fee.
Join our agency — look for real ISBN codes in your classroom or library. Are their check digits correct? Sometimes mistakes really do happen!
Common types of errors include:
- A digit's value is changed
- Two digits next to each other are swapped
- A digit is accidentally added
- A digit is accidentally left out
Can you find a book with the letter X as its check digit? It shouldn't be too hard — about 1 in every 11 books should have one.
What kinds of errors might slip through without being caught? Can you change one digit and still end up with the correct check digit? What if you swap two digits next to each other (a very common typing mistake)?
What's It All About?
Imagine you're depositing $10 in cash into your bank account. The teller types in the amount, and it gets sent to a central computer. But suppose some interference affects the signal while it's traveling, and the code for $10 accidentally becomes $1,000. That might sound great if you're the customer — but it's a serious problem for the bank!
This is why it's so important to catch errors in data that's being transmitted (sent from one place to another). A computer receiving data needs a way to check that nothing got scrambled by electrical interference along the way. Sometimes, if an error is caught, the original data can simply be sent again. But that's not always possible — for example, if a disk or tape has been damaged by magnetic fields, electrical interference, heat, or physical damage. And if data is coming from a spacecraft deep in space, waiting for it to be resent could take forever! (In fact, it takes just over half an hour for a radio signal to travel from Jupiter to Earth, even at their closest distance.)
That's why we need two abilities: error detection (recognizing that data has been corrupted) and error correction (figuring out what the original data should have been).
The same method used in the "Card Flip" game is used inside real computers. By arranging bits (the basic units of computer data) into imaginary rows and columns, and adding parity bits to each one, a computer can not only detect that an error occurred — it can pinpoint exactly where it happened. The incorrect bit can then be flipped back to its proper value. That's error correction in action!
Of course, real computers often use more advanced error-control systems that can detect and fix multiple errors at once. In fact, a large portion of a computer's hard disk is set aside just for correcting errors, so the disk keeps working reliably even if parts of it start to fail. These advanced systems are closely related to the parity method you just learned.
And to finish off, here's a joke you'll appreciate after doing this activity:
Q: What do you call this: "Pieces of nine, pieces of nine"?
A: A parroty error.
Solutions and Hints
Errors that would slip past undetected are ones where one digit increases while another decreases by the same amount — since the total sum could end up looking the same, even though the number is wrong.
Original licensed under CC BY-NC-SA 4.0. This adaptation is provided free by OER.ai.