Play n Tools

Free tools & games for everyone

Free · No sign-up · No accounts

Error-detecting codes lab

See how computers catch and fix errors: parity, Hamming codes that repair a flipped bit, CRC long division step by step, checksums and Luhn digits.

Two-dimensional parity: find the flipped bit

Each row and column has its own parity bit, worked out when the block was sent. Press a data bit to flip it, as noise would.

How to use

  1. Parity: type bits to see the even and odd parity bit. In the grid, press a bit to flip it: the failing row and column checks point straight at it. Flip two bits to see when parity gets fooled.
  2. Hamming code: type 4 data bits and press Encode. Press any bit of the codeword to flip it; the syndrome names the position of a single error so it can be fixed. Tick the extra parity bit to also detect (not fix) two errors.
  3. CRC: type message bits and pick a generator polynomial to see the long division (XOR instead of subtraction) and the remainder that is sent. Type text below to get its standard CRC-8, CRC-16 and CRC-32.
  4. Checksums & Luhn: see the Internet checksum, Fletcher-16 and Adler-32 of text, and the Luhn check digit used on card and ID numbers.
  5. Error test: flip random bits in thousands of random messages and see what share each scheme notices.

Keyboard and touch

TabMove between tabs, bits and boxes
Enter or Space on a bitFlip it
Enter in a boxWork it out

Tips

  • Detecting is cheaper than correcting: one parity bit detects any single error, but pinning down where it is takes more bits (3 for every 4 data bits in Hamming (7,4)).
  • A CRC with an r-bit remainder catches every burst of errors up to r bits long. Try bursts of 8 and 17 in the error test.
  • Checksums and CRCs catch accidents, not attacks: anyone can change data and fix the CRC. For tampering, use a cryptographic hash (see the Hash & HMAC generator).
  • The Luhn digit catches every single wrong digit and most swaps of two neighbouring digits, which is why card numbers use it. It is not a sign that a number is real.
  • The text "123456789" is the standard test message for CRCs; the CRC-32 of it is CBF43926.

About this lab

Hamming (7,4) puts parity bits at positions 1, 2 and 4; each checks the positions whose binary number contains it, so the failing checks spell out the position of a single error (the syndrome). With an eighth overall parity bit (SECDED), a non-zero syndrome with the overall check passing means two errors. CRCs divide the message, followed by r zeros, by the generator polynomial in arithmetic modulo 2 and send the remainder. The standard values use CRC-8 (polynomial 0x07, start 0), CRC-16/CCITT-FALSE (0x1021, start 0xFFFF) and CRC-32 (reflected 0xEDB88320, start and final XOR 0xFFFFFFFF, as in zip and Ethernet).

The Internet checksum is the ones'-complement sum of 16-bit words (RFC 1071); Fletcher-16 and Adler-32 keep two running sums modulo 255 and 65,521. Text is turned into bytes as UTF-8. The error test uses a seeded random generator, so the same settings always give the same result. Everything runs in your browser.

See you tomorrow!

A fresh daily puzzle every morning, and new tools added every month.

Browse every product