Hamming code calculator
The data word 1011 encodes to 0110011: three even-parity bits go into positions 1, 2 and 4, and your four bits fill positions 3, 5, 6 and 7. Check homework or draw a coverage diagram with each parity bit shown. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Data
- 1011
- Encoded
- 0110011
- P1
- 0
- P2
- 1
- P4
- 0
The Hamming(7,4) code is the first single-error-correcting binary code most engineers and students actually implement: four information bits become a seven-bit word after three even-parity bits are inserted at the power-of-two positions. This Hamming code calculator takes a four-bit data word, places those bits at positions three, five, six, and seven, computes p1, p2, and p4 from the textbook coverage sets, and returns the seven-bit encoded word together with each parity bit. The contract is strict.
How Hamming(7,4) places data bits and computes parity
A Hamming(7,4) encoder maps a four-bit data word onto a seven-bit codeword that later lets a decoder locate any single flipped bit from a three-bit syndrome. Positions in the transmitted word are numbered from one to seven. Parity bits occupy the powers of two: position one is p1, position two is p2, and position four is p4.
The four data bits fill the remaining positions in order, so position three is the first data bit d1, position five is d2, position six is d3, and position seven is d4. The encoded word is the concatenation p1, p2, d1, p4, d2, d3, d4. The classroom vector 1011 therefore yields p1 equal to zero, p2 equal to one, p4 equal to zero, and the seven-bit string 0110011.
The all-zero data word encodes as 0000000, and the all-one data word 1111 encodes as 1111111, which are useful goldens for tests. This capability encodes only; it does not decode a received seven-bit word, compute a syndrome, or correct an error.
Where a Hamming(7,4) encoder earns its keep
Computer-engineering courses use a Hamming code calculator so learners can check the seven-bit word for arbitrary four-bit homework without mixing up which positions are parity bits. Interview and exam platforms need a deterministic oracle that rejects a three-bit or five-bit string instead of silently padding, because padding would mark a wrong student answer as correct. Failed validation does not consume balance.
Keep requests small, treat encoded as the copyable primary result, and use p1, p2, and p4 when you are drawing the coverage diagram for a lecture slide. This tool does not replace a general ECC library: it is the Hamming(7,4) encoder students and tests actually search for, not a variable-length Hamming constructor and not a decoder.
What you can do with it
Classroom Hamming(7,4) drills
Let students submit a four-bit data word and compare encoded, p1, p2, and p4 against textbook even-parity placement at positions one, two, and four.
Exam and interview oracles
Grade Hamming-code items with a deterministic encoder that rejects any string that is not exactly four binary digits instead of silently padding.
FAQ
How do I encode four bits with the Hamming(7,4) code?
Send data as a string of exactly four binary digits, for example 1011.
What happens if the input is not exactly four binary digits?
Three-bit fragments, five-bit overflows, empty strings, and non-binary characters are rejected and not billed.
Which parity convention does this Hamming code use?
Even parity, the textbook Hamming(7,4) convention. p1, p2, and p4 are chosen so each coverage set contains an even number of ones.
Where are the parity bits placed in the seven-bit word?
At the power-of-two positions: p1 at position one, p2 at position two, p4 at position four. Data bits occupy positions three, five, six, and seven, so the layout is p1 p2 d1 p4 d2 d3 d4.
Can this tool decode or correct a received seven-bit word?
No. It only encodes, turning four data bits into a seven-bit word. Working out the syndrome of a received word and fixing a flipped bit is a decoder's job, which this tool does not do.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/enc/hamming-code \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"data":"1011"}'const res = await fetch("https://api.kit.forhosting.com/enc/hamming-code", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"data": "1011"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/enc/hamming-code",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"data": "1011"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/enc/hamming-code", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"data":"1011"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"data":"1011"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/enc/hamming-code", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"data": "1011"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "enc.hamming_code",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
After optional spaces, underscores, colons, hyphens, and commas are stripped, the input must be exactly four characters from the set zero and one; any other length or a non-binary character fails with invalid_input and is not billed.
How Hamming(7,4) places data bits and computes parity
This endpoint uses even parity, the convention in every standard Hamming(7,4) lecture. p1 is chosen so positions one, three, five, and seven contain an even number of ones, which means p1 equals d1 XOR d2 XOR d4. p2 covers positions two, three, six, and seven, so p2 equals d1 XOR d3 XOR d4. p4 covers positions four, five, six, and seven, so p4 equals d2 XOR d3 XOR d4.
Input contract, response fields, and invalid four-bit words
On success the body echoes the normalized four-bit data string, returns encoded as the seven-bit Hamming codeword, reports the three parity bits p1, p2, and p4 and the four placed data bits d1 through d4 as integers zero or one, lists positions as a seven-element array in index order from position one to position seven, and includes layout as the mnemonic p1 p2 d1 p4 d2 d3 d4 plus parity set to even so clients can display the convention without guessing. POST a JSON body with one required field named data: a string of exactly four binary digits. Alias keys bits, word, text, value, and input are accepted when data is omitted, and they are resolved in that order. After stripping, the remaining characters must be exactly four symbols from the set zero and one; a missing field, an empty string, a three-bit fragment, a five-bit overflow, and any letter or digit other than zero and one all fail with invalid_input that names the data field. Those failures are not billed. Pair the encoded string with your own decoder if you need a syndrome; this endpoint does not invert bits or report which position failed.
Integration use cases
Firmware ECC unit tests
Pin Hamming(7,4) goldens such as 1011 encoding as 0110011 in CI before wiring a larger Hamming or SECDED block in memory firmware.
Technical questions
What does the Hamming code calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.