In information theory, the Hamming distance between two strings or vectors of equal length is the number of positions at which the corresponding symbols are different.
[clarification needed] For binary strings a and b the Hamming distance is equal to the number of ones (population count) in a XOR b.
[3] The metric space of length-n binary strings, with the Hamming distance, is known as the Hamming cube; it is equivalent as a metric space to the set of distances between vertices in a hypercube graph.
The minimum Hamming distance or minimum distance (usually denoted by dmin) is used to define some essential notions in coding theory, such as error detecting and error correcting codes.
This is also understood geometrically as any closed balls of radius k centered on distinct codewords being disjoint.
The codeword "000" and the single bit error words "001","010","100" are all less than or equal to the Hamming distance of 1 to "000".
Likewise, codeword "111" and its single bit error words "110","101" and "011" are all within 1 Hamming distance of the original "111".
[6] It is used in telecommunication to count the number of flipped bits in a fixed-length binary word as an estimate of error, and therefore is sometimes called the signal distance.
The following function, written in Python 3, returns the Hamming distance between two strings: Or, in a shorter expression: The function hamming_distance(), implemented in Python 3, computes the Hamming distance between two strings (or other iterable objects) of equal length by creating a sequence of Boolean values indicating mismatches and matches between corresponding positions in the two inputs, then summing the sequence with True and False values, interpreted as one and zero, respectively.
The following C function will compute the Hamming distance of two integers (considered as binary values, that is, as sequences of bits).
The running time of this procedure is proportional to the Hamming distance rather than to the number of bits in the inputs.
It computes the bitwise exclusive or of the two inputs, and then finds the Hamming weight of the result (the number of nonzero bits) using an algorithm of Wegner (1960) that repeatedly finds and clears the lowest-order nonzero bit.