A parity bit is one extra bit sent or stored with a group of data bits so that a single-bit error can be detected.
The sender and receiver agree on a scheme first:
- Even parity: the data bits plus the parity bit together contain an even number of 1s.
- Odd parity: together they contain an odd number of 1s.
Generating the bit takes nothing but XOR gates:
- Even parity: P = XOR of all data bits. If the data already has an even count, P = 0; if odd, P = 1.
- Odd parity: P is the complement of that XOR.
Checking is just as cheap. The receiver XORs every bit it got, parity bit included. Under even parity the result should be 0. A result of 1 means an odd number of bits flipped, most likely one.
Limits worth knowing:
- Parity detects any odd number of flipped bits but misses an even number, since two flips leave the count's parity unchanged.
- It can't say which bit flipped, so it can't correct anything. Codes that correct errors use several check bits and rely on hamming distance.
The circuit that makes the bit is a parity generator, and the one that tests it is a parity checker. Both are XOR trees computing the odd function.