TwiddleLab / Code / How Computers Store Everything
The Parity Magic Trick
What you will learn
- A parity bit is an extra bit that makes the number of 1s even.
- If one bit flips on the way, the count turns odd: the error is detected.
- Parity on rows and columns also tells *where* a single flip is, so it can be fixed.
- Two flips can hide from a parity check, or leave too many suspects.
How the lesson goes
Flip any one card while I'm not looking. I'll tell you which one.
Let Pip look away, flip one card, then call Pip back.
The trick, slowly.
Step through: count the dark cards in every row, then every column.
Set up your own trick grid.
The 4 x 4 cards are random. Set the purple extra cards so every row and column has an even number of dark cards.
Parity.
Parity is whether a count is even or odd.
A parity bit is one extra bit added so the number of 1s is even. Dark card = 1, light card = 0.
Error detection: if a bit flips on the way, the count turns odd and the receiver knows something broke. With rows and columns it even knows where.
Be the magician: Pip flips, you find.
First your own grid, then bigger ones.
Computers do the same with bytes: 7 data bits and 1 parity bit.
Drag a 0 or a 1 into each purple slot so every byte has an even number of 1s.
Break the trick: Pip flipped two cards in one row.
Find the lines that raise the alarm. Odd plus odd is even: that is maths you'll meet again.
Bytes arrive with an even parity bit at the end. Which are damaged?
Count the 1s in all 8 bits.
No counts this time. Which card was flipped?
Tap it.
Which grid can the trick repair?
Tap it.
Previous lesson: Throw Away What You Won't Notice · Next lesson: Fixing Errors on the Fly · Part of the course: How Computers Store Everything
Lessons are interactive and need JavaScript. Turn it on to play them.