(also hamming metric)
Hamming distance, sometimes referred to as the hamming metric, is a method employed to determine the dissimilarity between two equal-length strings by tallying the number of positions where their respective symbols do not match. Within the realm of error detection and error correction codes, it calculates the bit flips needed to convert one binary code word into another.
For example, the Hamming distance between the binary strings “10101010“ and “11001100“ is 4, as there are four positions where the bits differ.
The Hamming distance is often compared to other string similarity metrics, such as the Levenshtein distance, which measures the minimum number of single-character edits (insertions, deletions, or substitutions) needed to change one string into another.
When using the Hamming distance, ensure that the input strings are of equal length. If not, consider using an alternative similarity metric, such as the Levenshtein distance or the Jaccard similarity.