The Hamming distance counts how many bit positions differ between two values. It is the foundation of error-correcting codes, perceptual-hash comparison, and sequence analysis. This tool computes it for any two non-negative integers, entered in binary, decimal, or hex, and shows exactly where the bits disagree.
How it works
Computing the Hamming distance reduces to two well-known bit operations:
diff = a XOR b // 1 wherever the bits differ
distance = popcount(diff) // count those 1 bits
XOR yields a 1 in every position where the two inputs disagree and a 0 where they match, so the population count of the XOR is precisely the number of differing positions. The tool left-pads both numbers to the same bit width before displaying them, matching the convention that the shorter value carries implicit leading zeros.
Example and notes
Comparing 10110110 and 11100100, the XOR is 01010010, which has three 1
bits — so the Hamming distance is 3. In coding theory the minimum Hamming
distance of a code sets its strength: a distance of d lets you detect up to
d − 1 errors and correct up to (d − 1) / 2. The same measure compares image
hashes (a small distance means visually similar) and counts mutations between
biological sequences. This calculator uses BigInt, so the values can be
arbitrarily large.