Hamming Distance
Jump to navigation
Jump to search
External
Internal
Overview
The Hamming distance between two string of equal length is the number of positions at which the corresponding symbols are different. In other words, it measures the minimum number of substitutions required to change on string into the other, or the minimum number of errors that could have transformed one string into the other.
Implementations
Hamming Distance between Two Integers in Java
public static int hammingDistance(int i1, int i2) {
int setBits = 0;
int xor = i1 ^ i2;
while(xor > 0) {
setBits += xor & 1;
xor >>= 1;
}
return setBits;
}
Also see: