Binary Hamming Distance Calculator
Calculate the Hamming distance between two equal-length binary strings. Compare each bit position to see how many bits differ, how many match, and the percentage difference.
What Is Hamming Distance?
Hamming distance measures how many positions are different between two
equal-length strings. For binary values, each position is compared as either
0 or 1.
How to Calculate Binary Hamming Distance
1. Use Equal-Length Strings
Both binary strings must contain the same number of bit positions.
2. Compare Position 1
Check whether the first bits are equal or different.
3. Continue Position by Position
Compare every corresponding pair of bits.
4. Count Differences
Each unequal bit pair adds one to the Hamming distance.
Hamming Distance Formula
For equal-length binary strings A and B, Hamming
distance can be expressed as:
For binary data, XOR also identifies the differing positions. An XOR result
contains 1 wherever the two input bits differ.
Example: 11001 vs 10011
Binary Hamming Distance Examples
| Binary A | Binary B | Distance |
|---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 1 | 0 |
00 | 11 | 2 |
101 | 111 | 1 |
1010 | 1111 | 2 |
0000 | 1111 | 4 |
11001 | 10011 | 2 |
101010 | 010101 | 6 |
11111111 | 11111111 | 0 |
Hamming Distance and XOR
For binary strings, XOR provides a convenient way to identify mismatched positions.
01010 contains two 1 bits.
Therefore:
Hamming distance = Hamming weight of XOR result = 2
Hamming Weight vs Hamming Distance
| Measurement | What It Measures |
|---|---|
| Hamming Weight | Number of 1 bits in one binary string |
| Hamming Distance | Number of differing positions between two strings |
For binary strings, the Hamming distance between A and B equals the Hamming
weight of A XOR B.
What Is Difference Percentage?
Difference percentage shows what portion of all compared bit positions differ.
Why Must the Strings Be the Same Length?
Traditional Hamming distance compares corresponding positions. If two strings have different lengths, there is no one-to-one position comparison for all characters.
Therefore, this calculator requires equal-length binary strings rather than automatically adding or removing leading zeros.
Where Is Hamming Distance Used?
Error Detection
Hamming distance is important when studying how many bit errors separate code words.
Error-Correcting Codes
Coding systems use minimum Hamming distance to determine error-detection and correction capability.
Digital Communications
Bit differences can be used to compare transmitted and received binary data.
Computer Science
Hamming distance appears in algorithms, information theory, coding, and binary similarity analysis.
Common Hamming Distance Mistakes
Using Different-Length Inputs
Standard Hamming distance requires corresponding positions, so the strings should have equal length.
Counting Matching Bits
The distance counts differences, not matches.
Removing Leading Zeros
Do not normalize the strings before comparison; each supplied bit position matters.
Confusing Distance with Weight
Weight analyzes one string, while distance compares two strings.