The Hamming distance between two strings of equal length counts the number of positions where the symbols differ. In coding theory, it is denoted and calculated as
where equals 1 if the symbols differ and 0 otherwise.
Originally introduced by Richard Hamming in the context of error-correcting codes, this metric quantifies how many substitutions are needed to change one string into another when no insertions or deletions are allowed. It provides a simple yet powerful way to detect and correct single-bit errors in data transmission by ensuring code words differ in enough positions.
Beyond communications, Hamming distance appears in DNA analysis, cryptography, and clustering algorithms. Whenever objects can be encoded as fixed-length strings—such as bit patterns, nucleotide sequences, or categorical labels—the metric offers a direct comparison. If the alphabet consists of {0,1}, Hamming distance coincides with vector addition modulo 2, revealing connections to linear algebra over finite fields.
Enter two strings of identical length and click the compute button. The script loops over each character, incrementing a counter whenever the symbols differ. The final count represents the Hamming distance. If the strings have different lengths, the calculator reports an error, since the measure is only defined for equal-sized inputs.
Consider and . Comparing bit by bit, we find differences in positions 3, 4, and 7, so . This small number suggests the sequences are similar, whereas a larger distance would indicate greater deviation.
The simplicity of Hamming distance belies its importance. Many sophisticated algorithms in error correction and cryptography rely on this basic idea to measure closeness or to design codes with desirable spacing properties. By experimenting with different strings, you can appreciate how even minor variations contribute to the distance and how redundancy in code words improves robustness against noise.
Compute Shannon entropy from probability values to quantify uncertainty in data.
Compute the aerodynamic or hydrodynamic drag force on an object using density, velocity, drag coefficient, and cross-sectional area.
Convert Raman shift values to scattered wavelengths for spectroscopy experiments.