Hamming Distance Calculator|Binary, Hex & Text Position Diff
Count the positions where two equal-length strings differ across binary, hex, and text modes. Hex inputs are expanded to 4 bits each before bit-level comparison, and every differing position is highlighted in red right next to the result.
💡 About this tool
The Hamming distance is the number of positions at which two equal-length strings have different symbols. It is the quick answer to "how many bits are off?" when you compare two register values, two hash digests, or two fixed-length codes.
Counting differing bits by hand gets error-prone fast once the strings grow past a byte or two. This tool returns the distance the moment you type and paints only the mismatched positions red, so you can see exactly where the drift is instead of scanning column by column. Hex mode expands each digit to its 4-bit binary form before counting, so a comparison like b4 vs e4 is measured at true bit resolution. Text mode compares symbol by symbol, which is handy for spotting a single wrong character in a serial number or part code.
Everything runs in your browser, and if the two inputs are not the same length the tool refuses to guess — it reports the mismatch and shows both lengths.
🧐 Frequently Asked Questions
What's the difference between Hamming and Levenshtein distance? Hamming distance compares two equal-length strings position-for-position and counts substitutions only — it never handles insertions or deletions. Levenshtein distance is the one to reach for when the strings differ in length or when you want to allow shifts between characters.
What happens if my two strings have different lengths? Hamming distance is only defined for equal-length strings, so the tool does not compute a value. It tells you the lengths don't match and shows both counts. Pad with leading zeros (or trim) to line them up.
How does hex mode count bits?
Each hex digit is expanded to its 4-bit binary form, then the bits are compared one by one. For example b4 (10110100) and e4 (11100100) differ in 2 bits, so the distance is 2.
Does this match the XOR method? Yes. XOR-ing the two values and counting the set bits in the result gives the same number. This tool reaches it by comparing positions directly.
Are spaces and letter case significant? Binary and hex modes ignore whitespace, and hex is case-insensitive. Text mode compares the characters exactly as you enter them.
📚 Why minimum distance matters
Hamming distance is the backbone of error-correcting codes: the larger the minimum distance between any two valid codewords, the more bit errors a code can detect and fix. A code whose minimum Hamming distance is 3 can not only detect a single-bit error but correct it — which is exactly where Hamming codes start.
You meet this idea every day without noticing. QR codes, barcodes, and ECC memory all lean on minimum-distance reasoning to repair the small read errors that creep in, so a smudge or a flipped bit doesn't corrupt the payload. A measure this simple turns out to be what keeps a lot of data intact in transit.