Hamming Code Calculator

Generate Hamming(7,4) error-correcting code for 4-bit data.

Calculator by SuperCalX: formulas, worked examples and 250+ free calculators.

Your values

Result

Enter your values and the result appears here.

Analysis

Interpretation of the current calculator output

Enter values to see detailed analysis and insights.

How to Use

Step-by-step instructions
  1. 1Enter 4 bits of data (e.g., 1011).
  2. 2The calculator will generate the 7-bit Hamming code.

Hamming(7,4)

Adds 3 parity bits to 4 data bits to allow correction of single-bit errors.
Code = p1 p2 d1 p4 d2 d3 d4

Variables:

p1Parity for bits 1, 3, 5, 7
p2Parity for bits 2, 3, 6, 7
p4Parity for bits 4, 5, 6, 7

Example

Data 1011

Inputs:

Data:1011

Steps:

  1. 1.d1=1, d2=0, d3=1, d4=1
  2. 2.p1 = (1+0+1)%2 = 0
  3. 3.p2 = (1+1+1)%2 = 1
  4. 4.p4 = (0+1+1)%2 = 0
  5. 5.Code = 0110011
Result:
0110011

Hamming Code Calculator: the short answer

Hamming(7,4) adds three parity bits to four data bits so that any single-bit error can be found and corrected. The bits are ordered p1 p2 d1 p4 d2 d3 d4, with p1 = d1⊕d2⊕d4, p2 = d1⊕d3⊕d4 and p4 = d2⊕d3⊕d4. Data 1011 encodes to 0110011.

  • Parity bits sit at positions that are powers of two: 1, 2 and 4.
  • On receipt, recomputing the parities gives a 3-bit syndrome that points to the wrong bit.
  • An extra overall parity bit (SECDED) also detects double errors, as used in ECC memory.

By the SuperCalX team · Reviewed by Dr. Ahmed Mortuza Saleque, founder and editor · Last reviewed · How we check our calculators

Correcting an error

Suppose 0110011 arrives as 0110111 (bit 5 flipped). Checking p1 over positions 1, 3, 5, 7 fails (1), p2 over 2, 3, 6, 7 passes (0) and p4 over 4, 5, 6, 7 fails (1). Reading the syndrome as p4 p2 p1 = 101 = 5 identifies bit 5, which is flipped back.

Where Hamming codes are used

Worked examples

Encode 1011

  1. d1 = 1, d2 = 0, d3 = 1, d4 = 1.
  2. p1 = 1⊕0⊕1 = 0; p2 = 1⊕1⊕1 = 1; p4 = 0⊕1⊕1 = 0.
  3. Order p1 p2 d1 p4 d2 d3 d4.

0110011.

Common mistakes

  • Placing parity bits at the end rather than at positions 1, 2 and 4.

Hamming Code Calculator FAQ

How many errors can Hamming(7,4) correct?

One per 7-bit block. Two errors are miscorrected unless an extra parity bit is added.

What is the code rate?

4/7, about 57%, since 4 of every 7 bits carry data.

What errors can it fix?

Hamming(7,4) can detect and correct any single-bit error. It can detect (but not correct) double-bit errors.

Add this calculator to your website

Teachers, bloggers and businesses can show the Hamming Code Calculator on their own pages for free. Copy this code and paste it into your page's HTML:

Please keep the credit link so readers can find the formula, worked examples and guide.