CalculateQuestion 1 · Apply
Loading…
By the end you can add a parity bit to a byte, compute a block check character and a checksum, explain how each detects corruption, and say what each one can miss.
Data does not travel perfectly. Electrical noise on a cable, a weak Wi-Fi signal or a scratch on a disc can flip a bit from 0 to 1 or from 1 to 0.
The receiver then holds a value the sender never sent.
Validation cannot help: the corrupted value may be perfectly acceptable. Verification cannot compare with a source document either, because nobody is typing — one computer is talking to another.
So the sender and receiver agree on a check value that travels with the data. The receiver recalculates it and compares.
If the two disagree, something changed on the way and the data must be resent.
Parity check (byte parity)
A parity bit is one extra bit added to a byte so that the total number of 1s in the byte (including the parity bit) is either always even (even parity) or always odd (odd parity).
The sender and receiver must agree which convention is in use, otherwise every byte looks wrong.
Example: send the byte 10110010 using even parity.
10110010 has four 1s.010110010 is transmitted (parity bit first, by this convention).With odd parity the total must be odd, so the parity bit would be 1, making five 1s.
| Data byte | 1s in data | Even parity bit | Odd parity bit |
|---|---|---|---|
10110010 |
4 | 0 | 1 |
01101101 |
5 | 1 | 0 |
11110000 |
4 | 0 | 1 |
01011010 |
4 | 0 | 1 |
At the receiver, the parity of the whole byte is recalculated. If it no longer matches the agreed convention, the byte is corrupt and is rejected.
Parity catches any odd number of flipped bits in a byte, because an odd number of flips changes the count from even to odd (or the reverse).
It misses any even number of flips, because two flips leave the count's parity unchanged. Flip two bits of 10110010 and it still has an even number of 1s, so even parity still passes — even though the byte is now wrong.
That is a serious gap: noise often damages a short burst of adjacent bits, which can be two of them.
Block parity (block check character)
Block parity adds a whole extra byte, the block check character (BCC), at the end of a block of bytes.
Each bit position is checked down the whole block: the BCC has a 0 or 1 in that position so that the column contains an even number of 1s (for even parity). In other words the BCC is the exclusive OR of all the data bytes.
Take four bytes and compute the BCC with even parity, working down each bit column.
byte 1 0 1 0 1 1 0 1 0
byte 2 0 0 1 1 0 1 0 1
byte 3 1 1 1 0 0 0 1 1
byte 4 1 0 0 1 0 1 1 0
-------------------------
BCC 0 0 0 1 1 0 1 0
Check one column: the leftmost column is 0, 0, 1, 1 — two 1s, already even, so the BCC bit is 0. The fourth column is 1, 1, 0, 1 — three 1s, odd, so the BCC bit is 1.
Now suppose two bits flip inside byte 1: 01011010 becomes 10011010. Byte 1 still has four 1s, so byte parity passes and would have missed the error.
But two columns have changed, so recalculating the BCC gives 11011010, which no longer matches the transmitted 00011010. Block parity catches the error that byte parity missed.
Checksum
A checksum is a value calculated from all the bytes in a block — commonly their total, reduced modulo 256 — which is sent with the data. The receiver adds the bytes again and compares the two checksums.
A checksum is cheap to calculate and covers the whole block in a single number, so it is used for files, network packets and downloads.
Example: a block contains the byte values 120, 90, 30 and 10.
If one byte arrives as 91 instead of 90, the receiver's total is 251, which does not match 250, so the block is rejected and requested again.
Limits. A checksum is a single number, so errors can cancel: one byte arriving too high and another too low can leave the total unchanged. It is generally stronger than byte parity for large blocks, but like parity it can only detect, never repair — the fix is to resend the data.