Hamming Distance Calculator
Count differing bits between two equal binary strings.
What it does
Hamming distance measures how many bits flip between two equal strings. Error codes use it to tell how many flips they can spot or fix. Larger distance means easier separation.
The tool above takes two binary strings and returns distance, similarity, and length. The defaults 1010 and 1001 match the worked example, so the page opens showing distance 2. Type new strings to update all three results.
Counting is positional: compare first with first, second with second, and tally mismatches. Here positions three and four differ, so distance is 2 over length 4 for 50.0 percent same.
Use this for code theory, barcodes, and DNA k-mers in binary form. For hex bytes with XOR totals use a checksum tool instead.
This page shows the method, one full hand checked example at 1010 vs 1001, a reference table, and practice checks that run through the tool.
How to use
- Type first string with 0 and 1 only.
- Type second string with equal length.
- Keep each 1 to 64 bits.
- Read Distance as mismatch count.
- Read Similarity as same percent.
- Pad shorter codes before comparing.
Formula
- distance
- Differing positions.
- length
- Shared string length.
- similarity
- Same share in percent.
Equal length required. Spaces and dashes strip first. Non binary stops with a message.
Worked example
Example: 1010 vs 1001
Compare 4 bit strings 1010 and 1001.
- Align: 1-1, 0-0, 1-0, 0-1.
- First two match, last two differ.
- Distance 2.
- Same: 4 minus 2 = 2.
- Similarity: 100 x 2/4 = 50.0 %.
- Length 4 bits.
Reference table
| Pair | Distance | Similarity |
|---|---|---|
| 1010 vs 1001 | 2 | 50.0 % |
| 1111 vs 0000 | 4 | 0.0 % |
| 1010 vs 1010 | 0 | 100.0 % |
Limits
- Equal length binary only, 1 to 64 bits.
- Counts substitutions, not inserts or deletes.
- No code correction here, only distance.
- Text needs binary encode first.
Common mistakes
- Comparing different lengths without padding.
- Counting matches instead of mismatches.
- Pasting spaces that change length. This tool strips them first.
- Using hex without binary convert.
- Reading similarity as distance.
Try it yourself
Quick checks. Answers sit tucked under each question.
1111 vs 0000?
Distance 4, similarity 0.0 %, length 4 bits.
1010 vs 1010?
Distance 0, similarity 100.0 %, length 4 bits.
Questions
1010 vs 1001?
Distance 2.
Similarity?
Same over length times 100.
Different lengths?
Error here. Pad first.
Max length?
64 bits each here.
Use?
Error detection spacing.
Hex?
Convert to binary first.