Hamming Distance Formula
Calculate the number of differing positions between two binary strings.
Used in error detection and correction coding.
The Formula
The Hamming distance counts how many bit positions differ between two strings of equal length. It measures how many single-bit errors would transform one string into the other.
Variables
| Symbol | Meaning |
|---|---|
| d(x, y) | Hamming distance between strings x and y |
| x, y | Two binary strings of equal length |
| xᵢ, yᵢ | The bit at position i in strings x and y |
Example 1
Find the Hamming distance between 1011101 and 1001001
Position 1: 1 vs 1 ✓
Position 2: 0 vs 0 ✓
Position 3: 1 vs 0 ✗
Position 4: 1 vs 1 ✓
Position 5: 1 vs 0 ✗
Position 6: 0 vs 0 ✓
Position 7: 1 vs 1 ✓
Hamming distance = 2
Example 2
Find the Hamming distance between "karolin" and "kathrin"
k-k ✓, a-a ✓, r-t ✗, o-h ✗, l-r ✗, i-i ✓, n-n ✓
Hamming distance = 3
When to Use It
Use the Hamming distance when:
- Designing error-detecting and error-correcting codes
- Measuring similarity between binary data or DNA sequences
- Implementing spell checkers or fuzzy matching
- Evaluating the reliability of communication channels