Computer ScienceExam code: 0984

Error Detection

Data Transmission

A parity check detects errors by adding a single extra bit (the ) to each byte so that the total number of 1s in the byte follows an agreed pattern.

The sender and receiver agree in advance whether they will use or odd parity:

  • Even parity: the total number of 1s in the byte (including the parity bit) must be even.
  • Odd parity: the total number of 1s in the byte (including the parity bit) must be odd.
Single parity-bit check from sender to receiver: the sender takes the data, computes a parity bit and appends it, then sends the byte across the transmission media; the receiver recomputes the parity bit and checks whether the byte has the agreed parity — if it is correct the data is accepted, otherwise it is rejected.
Source: Error Detection in Computer Networks by GeeksforGeeks

Setting the parity bit

To set the parity bit, the sender:

  1. Counts the 1s in the 7 data bits.
  2. If the count already matches the agreed parity, sets the parity bit to 0.
  3. If the count is the wrong parity, sets the parity bit to 1 to flip the total.

How the receiver detects an error

The receiver:

  1. Counts the 1s in every received byte.
  2. Checks whether the count matches the agreed parity.
  3. If yes, no error has been detected.
  4. If no, an error has occurred (and the data should be discarded or re-sent).

Worked example

Setting a parity bit and checking for an error

A sender and receiver have agreed to use odd parity. The sender wants to transmit the 7-bit data value 1 0 1 1 0 0 1. What parity bit must be added, and how does the receiver spot an error if one bit flips in transit?

Solution:

  • Count the 1s in the seven data bits 1011001: there are four, an even number.
  • Odd parity needs an odd total, so the parity bit must be 1, making five 1s. The transmitted byte, written parity bit first, is 1 1011001.
  • If the byte arrives intact, the receiver counts five 1s in 1 1011001. Five is odd, the parity matches, and no error is detected.
  • If the third data bit flips from 1 to 0, the receiver gets 1 1001001 and counts four 1s. Four is even but odd parity was agreed, so an error is detected and the byte is rejected or re-requested.

Exam tip

Explaining how a parity check detects errors

To explain how an odd (or even) parity check detects errors (4 marks), write the process as separate steps, each credited on its own: the 1s in each byte are counted, then a parity bit goes in front of the seven data bits before transmission, set so that the byte's total of 1s is odd (or even). After transmission the receiver counts again: the agreed parity means no error was detected, the other parity means an error was detected. Those two outcomes are separate points, so give both, and name the parity that was agreed.

Limitations of a single parity bit

Parity checks are cheap and quick but they cannot detect every error:

  • Two bits flipped in the same byte cancel each other out and the parity still matches.
  • A whole even-numbered group of bit flips also leaves the parity unchanged.
  • Bit transposition (two bits swapping positions) does not change the parity at all.
  • The parity check tells you whether an error has happened, but not which bit is wrong.

For better protection, the bytes are arranged into a parity block with an extra parity byte, described next.

Quick check

4 short questions on this note. See what has stuck, and where to look if something hasn't.

About 2 minutes

Build on this topic