Parity Bit
A parity bit is a single extra bit that makes the number of 1s in a group even or odd for error detection.
How it works
A parity bit is appended so the total count of 1 bits meets a chosen rule. Even parity sets the bit to make the count of 1s even; odd parity makes it odd. The receiver recomputes and compares.
What it catches
A parity bit detects any odd number of bit flips, including single-bit errors, the most common kind. But two flips cancel out, leaving parity unchanged, so it misses all even-numbered errors.
Detection, not correction
Parity tells you an error occurred but not where, so it cannot correct anything. Locating and fixing errors requires more redundancy, as in Hamming codes, which arrange multiple parity bits over overlapping groups.
Computing parity
Parity is the XOR of all data bits: XOR yields 1 when the number of 1 inputs is odd. This makes parity cheap to compute in hardware with a tree of XOR gates.
Uses
Parity appears in memory (a parity bit per byte), serial protocols, and as the building block of larger schemes. Two-dimensional parity over rows and columns can even locate a single error by its intersection.
def parity(x):
p = 0
while x:
p ^= 1
x &= x - 1 # clear lowest set bit
return p # 1 if odd number of 1s
print(parity(0b1011)) # 1