Skip to content
IGCSE·Tuition
Computer Science · Lessons

Explain parity using a worked example

Parity looks like a counting trick, yet it is easy to count correctly and still say the wrong thing about what it proves.

On this page
  1. How do you work out a parity bit?
  2. Worked example
  3. What mistake do students make?
  4. Check yourself
  5. Where this leads next

Parity adds one extra bit to each group of bits so that the number of 1s is always even (even parity) or always odd (odd parity). The receiver counts the 1s again. If the count has the wrong parity, an error has occurred.

This lesson builds on serial and parallel transfer and on the binary patterns from representing numbers and text.

How do you work out a parity bit?

  1. Count the 1s in the data bits.
  2. For even parity, make the total even. If the count is odd, the parity bit is 1. If it is even, the parity bit is 0.
  3. For odd parity, make the total odd. If the count is even, the parity bit is 1. If it is odd, the parity bit is 0.
  4. Attach the parity bit to the data. Agree in advance where it goes, and in this lesson it goes at the end.

Worked example

Send the 7-bit pattern 1011001 using even parity.

Step 1, count. The bits are 1,0,1,1,0,0,1. The 1s number 4.

Step 2, decide. 4 is already even, so the parity bit is 0.

Step 3, transmit. The byte sent is 10110010.

Step 4, receive without error. The receiver counts 1s in 10110010 and again gets 4, which is even. The check passes.

Step 5, one bit flips. Suppose the byte arrives as 10010010. The 1s now number 3, which is odd, so the receiver reports an error.

Here is the same counting in Cambridge-style pseudocode for the 7 data bits:

count ← 0
FOR i ← 1 TO 7
   IF Bits[i] = 1 THEN
      count ← count + 1
   ENDIF
NEXT i
IF count MOD 2 = 0 THEN
   parity ← 0
ELSE
   parity ← 1
ENDIF

Trace for 1011001: after i=1 count is 1, i=2 stays 1, i=3 gives 2, i=4 gives 3, i=5 stays 3, i=6 stays 3, i=7 gives 4. Then 4 MOD 2 = 0, so parity = 0. This matches the hand count.

What mistake do students make?

A common conclusion is: “The parity check passed, so the data is correct.”

That is not safe. Take the byte 10110010 above and flip two bits, the second and the fourth, to get 11100010. The 1s still number 4, so the check passes even though the data is wrong. The correction is to write: “Parity check passed, so no error was detected, but an even number of changed bits could still be hidden.”

Check yourself

1. Find the even parity bit for 1110110.

Show answer

1s: 1,1,1,0,1,1,0 gives 5. Five is odd, so the parity bit must be 1. The full byte is 11101101, which has 6 ones, an even number.

2. Odd parity is used. A byte arrives as 01100110. Is an error detected?

Show answer

1s: 0,1,1,0,0,1,1,0 gives 4, which is even. Odd parity needs an odd count, so an error is detected.

3. Explain why two flipped bits might not be detected.

Show answer

Each flip changes the count of 1s by one. Two flips can cancel out, so the count has the same parity and the check appears to pass.

Where this leads next

Parity is the simplest check. The next lesson looks at a checksum that covers a whole block of data. You can test your counting in the practice set or step through the loop above in the restricted pseudocode trace trainer.

If your counting is accurate but the wording of explanations still loses marks, our teachers can help in online one-to-one Computer Science tuition.

Questions people ask

What is the difference between even and odd parity?

With even parity the parity bit is chosen so the total number of 1s in the byte, including the parity bit, is even. With odd parity the total must be odd. The sender and receiver must agree on which type is used before any data is sent.

Can parity tell me which bit is wrong?

No. Parity only shows that the count of 1s is wrong, so at least one bit changed. It cannot say which one, so the receiver usually asks for the data to be sent again. Correcting a bit needs extra information, as the later lesson on correction explains.

Why can parity miss an error?

If two bits flip, the number of 1s may change by 2 or stay the same, so the parity still looks right. A parity check can detect an odd number of flipped bits but cannot detect an even number of them.

Updated:

Your next step

If you can find a parity bit but the explanation questions cost you marks, a one-to-one teacher can rehearse the exact wording with your own examples until it comes naturally.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service