Error detection and correction

Contents

Why errors happen

Communication channels are often “noisy”, meaning data can sometimes get altered (corrupted) during transmission. These errors happen when other signals interfere with your data transmission and cause some or all of the data to not be received, or to be changed.

Error detection and correction attempts to detect this corruption and fix it silently without the user even knowing.

Whenever any data is transmitted, there is a risk of corruption. Error detection is built into computer systems and protocols to attempt to eliminate these issues.

These detection algorithms usually involve adding another piece of data to the end of the payload. This data is recalculated at the other end and compared to the value transmitted.

Error detection methods

Repetition

This is the simplest form of error detection.

When you send data, it is repeated an agreed number of times. For example, if you were sending 1010, your device might actually send 1010 1010 1010.

When the data is received, the device checks all the repeated data to see if it matches. If it doesn’t the assumption is that the data was corrupted, so your device asks for it to be resent.

Note: sometimes the algorithm operates in a majority mode where it will assume the value which is found the most. E.g. 1010 1001 1001 would be assumed to be 1001.

This algorithm will not always detect every error: there is a chance that all the data could be corrupted or altered in the same way. This method is also wasteful as the entire data must be repeated multiple times.

Pros

Cons

Parity scheme

Another simple form of error detection.

Instead of repeating the entire piece of data, we just add another bit to check if the rest of the data is likely to be correct. This is more commonly used within components of a computer, such as when copying to/from RAM or cache.

Even parity works by counting the number of 1 bits in a word (group of bits). If it’s an odd number, we add a parity bit of 1 to make the number of 1s even. Otherwise we keep it as a 0.

Pros

Cons

Example of even parity

Check digits

Check digits are commonly used in barcodes.

For example, an ISBN barcode consist of 12 digits for data, and an additional check digit. The check digit is calculated from the data digits. The scanner can recalculate this bit to check if the barcode scanned correctly.

Checksum

Checksums are more generalised versions of check digits. They are often used for transmitting files from one location to another.

The checksum algorithm is run on the file data, which then produces a value called the “checksum”.

The file can be transmitted and run through the same algorithm by the recipient, then the checksums can be compared.

A change in even one bit in a series of binary data can change the entire checksum.

Common algorithms include:

Pros

Cons

Cyclic redundancy check (CRC)

A form of checksum calculated before transmission, and placed at the end of a data packet. It can also be used for checking for data corruption when storing files to disk, or for validating firmware versions during updates.

The algorithm applied to the data depends on cyclic codes. The whole packet is treated as a number and is divided by a specific value. The remainder of this calculation is used as the CRC.

The calculation gets repeated on the recipient’s end and if they don’t match, an error has occurred.

CRCs are redundant meaning that they don’t add anything to or change the data itself.

Pros

Cons

Overall implications of error detection