📅 March 4, 2015
The word parity originates from the Latin word par, meaning equal. Take the sport of golf, for example. A hole on a golf course is usually assigned a par number. If you sink the golf ball into the hole with the same number of strokes as the par, you are said to be on par — equal to the number of expected strokes. If you expend more strokes than the par, then you need practice, and you should probably try again.
An identical strategy applies to computers. Parity is an early form of error detection often used with serial communications, such as modems and serial ports, for example. An extra bit is appended to each data byte to make the total number of 1 bits even or odd. This extra bit, called the parity bit, is separate from the data byte, and it does not contain data information. It is only used to make the total number of 1 bits even or odd.
There are two main types of parity: Even parity and odd parity. Both operate in the same manner aside from the evenness or oddness.
This lesson focuses on 8-bit data even though the concept can apply to any number of data bits, such as 7-bit ASCII.
The goal of even parity is to ensure that the total number of 1 bits across all nine bits (8 data bits plus 1 parity bit) is even. The transmitting computer takes a data byte and counts the number of 1 bits. If even, then the parity bit is set to 0. If odd, then the parity bit is set to 1 to make the total number even.
Odd parity operates the same as even parity except that the parity bit is adjusted to reflect an odd number of bits. If the number of data bits is odd, then the parity bit is set to 0. If the number of data bits is even, then the parity bit is set to 1 to make the total number of bits odd.
Both computers, the sending and receiving, must be set to operate with the same parity system. Both must be configured for even parity or odd parity in order to correctly interpret the parity bit and determine if transmission errors occurred.
Parity is calculated for each byte sent. When a byte is received by the receiving computer, it performs its own calculation by counting the number of 1 bits in the data byte. Then, it calculates what should be the parity bit based upon the byte received. If the total number of 1 bits (including the parity bit) is even or odd, depending upon the preset even parity or odd parity, then the byte is determined to be valid.
However, if an even parity system counts an odd number of 1 bits or an odd parity system counts an even number of 1 bits, then the byte is determined to be invalid and must be discarded. The receiving system must ask the transmitting system to resend the byte, which will hopefully be transmitted again without errors.
There might be slight variations to this operation, but the basic premise remains the same: The received bits must match the transmitted bits, and the way parity helps determine this is by counting the number of 1 bits received.
Validated Corruption (When the wrong bits are seen as “Okay”)
Parity is an extremely simple system. It can only detect errors. It cannot correct them. Neither can parity determine which bit has been corrupted. This can produce a case where a byte can be corrupted but still be detected as valid by the receiving system.
For example, for even parity, suppose one computer sends the byte 10010001. The ninth parity bit will be set to 1 to produce an even number of bits (4). If one bit is inverted during transmission, then the receiving system will detect it.
However, if two bits are inverted, then the total number of bits remains even.
The receiving system would see the even number of bits in an even parity system and think that the byte is valid. This is one of the weaknesses of parity. There is no way to determine which or how many bits were corrupted if the corrupted result matches the even or odd parity requirements.
Despite this limitation, parity is still worth using since some detection is better than none at all, and it can be performed quickly at the hardware level.