Hamming Code Calculator (Encode + Check)
Enter binary data to generate a Hamming code, or paste a received codeword to detect and correct a single-bit error.
1) Generate Hamming Code
2) Check & Correct Received Codeword
What is a Hamming code?
Hamming code is a classic error-control coding method used in digital communication and memory systems. It adds carefully placed parity bits to your original data bits so the receiver can detect and correct a single-bit error. This is incredibly useful when sending data through noisy channels where occasional bit flips can happen.
The core idea is simple: parity bits are inserted at positions that are powers of two (1, 2, 4, 8, ...). Each parity bit checks a specific pattern of bit positions. When a codeword is checked later, those parity tests produce a binary number called the syndrome. If the syndrome is non-zero, it points directly to the bit position that is likely wrong.
How this calculator works
Encoding mode
- You enter your data bits (for example, 1011).
- The calculator computes how many parity bits are required using the rule 2^r >= m + r + 1, where m is number of data bits.
- It places parity bits at positions 1, 2, 4, 8, ... and fills data in all other positions.
- It calculates parity values using your selected parity type (even or odd), then outputs the final codeword.
Check/correct mode
- You paste a received codeword.
- The calculator runs parity checks and computes the syndrome.
- If syndrome is zero, no error is detected.
- If syndrome points to a valid position, the calculator flips that bit and shows the corrected codeword.
Quick example
Suppose data bits are 1011 with even parity. The algorithm inserts parity bits and generates a 7-bit Hamming code. If a single bit flips during transmission, parity checks produce a syndrome like 011 (binary 3), indicating bit position 3 is wrong. Flipping bit 3 restores the original valid codeword.
Where Hamming codes are used
- ECC memory systems
- Low-level communication protocols
- Embedded systems and microcontrollers
- Educational demonstrations of error detection and correction
Important limitations
Standard Hamming code is designed for single-error correction. It can reliably correct one flipped bit, but multiple simultaneous errors may produce incorrect correction. For stronger reliability, many systems use extended variants such as SECDED (Single Error Correction, Double Error Detection).
Tips for accurate results
- Use only 0 and 1 characters in inputs.
- Remove spaces before submitting (the tool also trims them automatically).
- Use the same parity type for encoding and checking.
- If communication is noisy, consider adding an overall parity bit for SECDED-style checks.