Enter the two strings (of equal length) into the calculator to calculate the Hamming Distance, which is the number of positions at which the corresponding characters differ.
Related Calculators
- Inner Product Calculator
- Channel Capacity Calculator
- Average Distance Calculator
- Distance From Point to Plane Calculator
- All Math and Numbers Calculators
Hamming Distance Formula
The following formula is used to calculate the Hamming Distance between two strings of equal length, where 1(·) is an indicator that equals 1 when the characters differ and 0 when they match:
HD = \sum_{i=1}^{n} \mathbf{1}\left(s_{1,i} \neq s_{2,i}\right)
Variables:
- HD is the Hamming Distance
- n is the length of the strings
- s1,i is the i-th character of the first string
- s2,i is the i-th character of the second string
To calculate the Hamming Distance, iterate over each character of the two strings. If the characters at the same position are not equal, increment the Hamming Distance by 1. Finally, the Hamming Distance is the total number of mismatched positions.
What is a Hamming Distance?
Hamming distance is a metric used in information theory and computer science to measure the difference between two strings of equal length. It is named after Richard Hamming, an American mathematician and computer scientist. The Hamming distance between two strings is calculated by comparing each corresponding pair of bits (or characters) in the two strings and counting the number of positions at which the corresponding bits are different. For example, the Hamming distance between the binary strings 1010101 and 1001001 is 3, because the bits differ at the third, fourth, and fifth positions. This concept is used in various applications including error detection and correction algorithms in computer science and genetics to measure genetic distance.
How to Calculate Hamming Distance?
The following steps outline how to calculate the Hamming Distance:
- First, write down the two strings that you want to compare.
- Next, count the number of positions where the characters in the two strings are different.
- Finally, the total count of different positions is the Hamming Distance.
Example Problem:
Use the following variables as an example problem to test your knowledge.
String 1: "101010"
String 2: "111010"
