1. Introduction
In this tutorial, we’ll study a simple technique for checking errors in the transmission of a binary string: parity checking.
Despite its simplicity and vulnerability, we can use this method in many applications for error prevention such as reading data from magnetic tapes and storing information in main memory.
2. Parity Control and Parity Bit
Let’s consider a message we codify as a binary string of 1 byte (8 bits) that is sent from sender to a receiver :
The transmission of involves the encoding, transport, and decoding of the message, operations potentially subject to errors. To be sure that receives a message that’s identical to the transmitted one, we need a check.
Of course, any potential control involves the transmission of a certain amount of information in addition to the original message. It is this extra information that allows the analysis of the information present in the message we receive.
One of the simplest methods of verification is the parity check. Parity is a control code we can use to prevent errors in data reception or reading on mass memories, adding redundant information.
This technique adds to each byte an additional bit , the parity bit. When writing data (bit sequence), we add a control bit set to 0 or 1 after each byte.
If within a byte, the bits at 1 are even in number, the additional bit will be set at 0. If the bits at 1 are odd, we add a bit at 1.
The sent message, , is therefore different from the original message, . Assuming that is at the end of each byte, we have:
3. Detection of Errors Through Parity Check
When receiver groups the bits received, it performs the check by simply counting the number of 1. If the case of error (a 0 becoming 1 or vice versa), will send a retransmission request.
A limitation of the parity check concerns the case in which an error occurs involving two bits of the word (or in general an even number of bits). In this case, the error would go unnoticed, as the parity would be maintained.
4. Calculation of the Parity Bit
4.1. Message Without Errors
For each byte, calculates the parity bit by performing an XOR between all the bits of the message :
Suppose . is:
The sent message becomes:
Now receives the message and, to detect its accuracy, XORs all the bits of . The result can only be 0 or 1. If it were 0 it would indicate that has arrived correctly, otherwise, it would detect an error.
4.2. Message with Errors
Instead, suppose the message arrives incorrectly. If, for example, changed its state from 1 to 0, we would have a situation like this:
and the operation carried out by would be:
which shows that there was an error.
4.3. Parity Check Failure
Let us consider the case in which the parity check fails when the number of errors in the transmission is even. Let:
Suppose that the values of two bits change and precisely and which invert their state from 1 to 0. We get:
The control operation carried out by is therefore:
from which deduce, erroneously, that there was no error in the transmission.
In these examples, calculates the parity bit, located at position 9, using the first 8 bits of the message. From an implementation point of view, it is sufficient to apply the XOR operator on all the bits of , including the parity bit. If there are no errors, the result is always 0. It is only necessary for and to know the position of in the sent message.
5. Conclusion
Parity checking is a method of checking for errors, not correcting them. There are techniques, such as the Hamming code, which serve both detection and correction.
Each error checking system in a message involves the transmission of information in addition to the original message.
Despite its simplicity, parity checking is a widely used technique in computer science. However, it is not without limitations, such as when the number of errors is even.