Parity check
A parity check 奇偶校验 adds one extra bit, the parity bit 奇偶校验位, to each byte. There are two types:
A parity bit is added to make the number of 1s even (or odd)
- even parity — the total number of 1s in the byte (including the parity bit) must be even;
- odd parity — the total number of 1s must be odd.
Example (even parity): the data 1011001 has four 1s, which is already even, so the parity bit is 0:
parity bit + data
0 1011001
To find an error: the receiver counts the 1s. If even parity was agreed but a byte arrives with an odd number of 1s, an error has happened during transmission.
A parity check cannot find every error. If two bits flip, the count may still look correct.
Worked example. A single parity bit tells you that an error happened, but not where. A parity block 奇偶校验块 can find the exact bit. Several bytes are sent together, each with a row parity bit, and one extra parity byte 奇偶校验字节 at the bottom holds a parity bit for each column. Even parity is used below, and one bit was flipped during transmission. Find it.
b1 b2 b3 b4 b5 | parity
byte 1 1 0 1 1 0 | 1
byte 2 0 1 1 0 1 | 1
byte 3 1 1 1 1 0 | 1 <- row: odd number of 1s
byte 4 0 0 1 1 0 | 0
------------------------------
parity 0 0 1 1 1 | 1
^ column b3: odd number of 1s
Row byte 3 breaks even parity, and column b3 breaks even parity. The flipped bit is where they cross: byte 3, bit b3. Changing it back from 1 to 0 repairs the data. A single parity bit only says an error happened; a parity block says exactly where, so the receiver can even fix it.
Checksum
A checksum 校验和 is a value worked out from all the data before sending. The receiver works out the checksum again from the data it received. If the two values do not match, an error has occurred and the data is resent.
Echo check
In an echo check 回送校验, the receiver sends the data back to the sender. The sender compares it with the original. If they differ, an error happened. (This needs the data to be sent twice, so it is slow.)
Automatic Repeat reQuest (ARQ)
Automatic Repeat reQuest 自动重传请求 (ARQ) uses messages called acknowledgements 确认.
- The receiver sends a positive acknowledgement if a packet arrived correctly, or a negative acknowledgement if it did not.
- The sender starts a timeout 超时 timer. If no positive acknowledgement comes back in time, the sender sends the packet again.
Check digit
A check digit 校验码 is an extra digit placed at the end of a number, worked out from the other digits. It is used to find mistakes when a number is typed in.
When the number is entered, the check digit is calculated again and compared. It can catch:
- an incorrect digit entered,
- a transposition error 换位错误 (two digits swapped, e.g. 21 typed as 12),
- a digit left out or an extra digit added,
- a phonetic error (a digit that sounds similar, e.g. 13 and 30).
Check digits are used in barcodes 条形码 and ISBNs (book numbers).