Parity bit
194467
223396854
2008-07-03T22:14:14Z
Thijs!bot
1392310
robot Modifying: [[pl:Kontrola parzystości]]
{| border="1" cellspacing="0" cellpadding="2" style="float: right; border-collapse: collapse;"
| style="width: 34%; background: #efefef;" align=center rowspan=2 | 7 bits of data
| style="background: #efefef;" align=center colspan=2 | byte with parity bit
|-
| '''1'''1010001
| '''0'''1010001
|-
| 1101001
| '''0'''1101001
| '''1'''1101001
|- ghfdjgkkioi90o970o9o09p[-0'/p-'
| 1111111
| '''1'''1111111
| '''0'''1111111
|}
A '''parity bit''' is a [[binary digit]] that is added to ensure that the number of bits with value of [[1 (number)|one]] in a given set of bits is always [[even number|even]] or [[odd number|odd]]. Parity bits are used as the simplest [[Error detection and correction|error detecting code]].
There are two variants of parity bits: '''even parity bit''' and '''odd parity bit'''. An even parity bit is set to 1 if the number of ones in a given set of bits is odd (making the ''total'' number of ones, including the parity bit, even). An odd parity bit is set to 1 if the number of ones in a given set of bits is even (making the ''total'' number of ones, including the parity bit, odd). Even parity is actually a special case of a [[cyclic redundancy check]] (CRC), where the 1-bit CRC is generated by the [[polynomial]] ''x''+1.
If the parity bit is present but not used, it may be referred to as '''mark parity''', where the parity bit is always 1, and '''space parity''', where the bit is always 0.
==Error detection==
If an odd number of bits (including the parity bit) are changed in [[Transmission (telecommunications)|transmission]] of a set of bits then parity bit will be incorrect and will thus indicate that an error in transition has occurred. Therefore, parity bit is an error detecting code, but is not an [[error detection and correction|error correcting code]] as there is no way to determine which particular bit is corrupted. The data must be discarded entirely, and [[automatic repeat-request | re-transmitted from scratch]]. On a noisy transmission medium a successful transmission could take a long time, or even never occur. Parity does have the advantage, however, that it is about the best possible code that uses only a single bit of space and it requires only a number of [[XOR gate]]s to generate. See [[Hamming code]] for an example of an error-correcting code.
For example, our parity bit can be computed as follows assuming we are sending a simple 4-bit value 1001, with the parity bit following on the right, and ^ denoting XOR gate:
Transmission sent using even parity:
A wants to transmit: 1001
A computes parity bit value: 1^0^0^1 = 0
A adds parity bit and sends: 10010
B receives: 10010
B computes overall parity: 1^0^0^1^0 = 0
B reports correct transmission after observing expected even result.
Transmission sent using odd parity:
A wants to transmit: 1001
A computes parity bit value: ~(1^0^0^1) = 1
A adds parity bit and sends: 10011
B receives: 10011
B computes overall parity: 1^0^0^1^1 = 1
B reports correct transmission after observing expected odd result.
This mechanism enables the detection of single bit errors, because if one bit gets flipped due to line noise, there will be an incorrect number of ones in the received data. In the two examples above, B's calculated parity value matches the parity bit in its received value, indicating there are no single bit errors. Consider the following example with a transmission error in the second bit:
Transmission sent using even parity:
A wants to transmit: 1001
A computes parity bit value: 1^0^0^1 = 0
A adds parity bit and sends: 10010
*** TRANSMISSION ERROR ***
B receives: 1'''1'''010
B computes overall parity: 1^1^0^1^0 = 1
B reports incorrect transmission after observing unexpected odd result.
B's calculated parity value (1) does not match the parity bit (0) in its received value, indicating the bit error. Here's the same example but now the parity bit itself gets corrupted:
B receives: 1001'''1'''
B computes overall parity: 1^0^0^1^1 = 1
B reports incorrect transmission after observing unexpected odd result.
Once again, B's computes an odd overall parity, indicating the bit error.
There is a limitation to parity schemes. A parity bit is only guaranteed to detect an odd number of bit errors. If an even number of bits have errors, the parity bit records the correct number of ones, even though the data is corrupt. (See also [[error detection and correction]].) Consider the same example as before with an even number of corrupted bits:
A wants to transmit: 1001
A computes even parity value: 1^0^0^1 = 0
A sends: 10010
*** TRANSMISSION ERROR ***
B receives: 1'''1'''01'''1'''
B computes overall parity: 1^1^0^1^1 = 0
B reports correct transmission though actually incorrect.
B observes even parity, as expected, thereby failing to catch the two bit errors.
==Usage==
Because of its simplicity, parity is used in many [[computer hardware|hardware]] applications where an operation can be repeated in case of difficulty, or where simply detecting the error is helpful. For example, the [[SCSI]] and [[PCI bus]]es use parity to detect transmission errors, and many [[microprocessor]] instruction [[cache]]s include parity protection. Because the I-cache data is just a copy of [[main memory]], it can be thrown away and re-fetched if it is found to be corrupted.
In [[serial communications|serial]] [[data transmission]], a common format is 7 data bits, an even parity bit, and one or two [[stop bit]]s. This format neatly accommodates all the 7-bit [[ASCII]].
==External links==
* [http://groups.google.com/group/comp.lang.c/msg/e65b8577d041435b?hl=en& Quick way to get the even parity of an integer]
* [http://graphics.stanford.edu/~seander/bithacks.html Different methods of generating the parity bit, among other bit operations]
[[Category:Data transmission]]
[[Category:Error detection and correction]]
[[Category:Parity]]
[[af:Pariteitsbis]]
[[ca:Bit de paritat]]
[[cs:Paritní bit]]
[[da:Paritetsbit]]
[[de:Paritätsbit]]
[[es:Bit de paridad]]
[[ko:패리티 비트]]
[[it:Bit di parità]]
[[he:סיבית זוגיות]]
[[hu:Paritásbit]]
[[nl:Pariteitsbit]]
[[ja:パリティビット]]
[[nn:Paritetsbit]]
[[pl:Kontrola parzystości]]
[[pt:Paridade (telecomunicações)]]
[[ru:Бит чётности]]
[[sk:Parita (kontrolný súčet)]]
[[vi:Bit chẵn lẻ]]
[[zh:奇偶校验位]]