A parity bit is a simple checksum that counts the 1 bits in a byte stream and stores whether the total is even or odd. It is fast and easy to implement, but less reliable than CRC32 or cryptographic hash functions. section 7.7.4
A parity check follows a small validation loop:
- Count the 1 bits in the data. section 7.7.4
- Store one bit indicating whether the count is even or odd. section 7.7.4
- Read the data and saved checksum again, recompute the result, and treat mismatches as corruption. section 7.7.4
Counting bits in Rust
A Rust function can iterate over &[u8], call byte.count_ones(), add the counts, and convert the evenness test to a u8. For b"abc", the displayed bytes contain 10 one bits and produce 00000001; adding d produces 13 one bits and produces 00000000. section 7.7.4
Table 7.8 A simplistic evaluation of different checksum functions (view table figure)
Compare parity bits with CRC32 and cryptographic hash functions by result size, simplicity, speed, and reliability. section 7.7.4
