TOPICS
Search

Hamming Distance


The Hamming distance between two strings of equal length is the number of positions at which their symbols differ (Black 2006). For binary strings, this is the number of coordinates at which the corresponding vertices of a hypercube graph differ. For example, abc and bca have Hamming distance 3.

For binary strings x and y of length n,

 d_H(x,y)=w_H(x xor y),

where w_H is the Hamming weight and  xor denotes bitwise XOR. Indeed, a coordinate of x xor y is 1 iff the corresponding coordinates of x and y differ. For any binary string k of length n, applying the same XOR mask to both arguments gives

 d_H(x xor k,y xor k)=d_H(x,y).

Thus common XOR masking is an isometry of the binary string space.


See also

Edit Distance, Hamming Code, Hamming Graph, Hamming Weight, Hypercube, String, XOR

Explore with Wolfram|Alpha

References

Black, P. E. "Hamming Distance." In Dictionary of Algorithms and Data Structures (Ed. P. E. Black). National Institute of Standards and Technology, May 31, 2006. https://xlinux.nist.gov/dads/HTML/HammingDistance.html.Exoo, G. "A Euclidean Ramsey Problem." Disc. Comput. Geom. 29, 223-227, 2003. https://doi.org/10.1007/s00454-002-0780-5.

Referenced on Wolfram|Alpha

Hamming Distance

Cite this as:

Weisstein, Eric W. "Hamming Distance." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/HammingDistance.html

Subject classifications