Intermediate

Hamming Distance Calculator

Compare two equal-length binary or hexadecimal strings and count the positions where their bits differ.

Input format

Hex strings are expanded to 4 bits per digit
Hamming distance
2

Number of positions where the bits differ

Total bit length
7
Matching bits
5
Differing bits
2
Differing positions (0-indexed)
2, 4
00.91.82.63.54.45.36.17027Hamming distance: 0 = identical, length = completely different
Step by step
  1. 1

    Total bit positions

    7
  2. 2

    Matching positions

    7 − 2 = 5
  3. 3

    Hamming distance

    7 − 5 = 2
    Number of positions where the bits differ — equivalent to popcount(A XOR B).
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

The Hamming distance between two equal-length binary strings is the number of bit positions where they differ, equal to the popcount of their XOR. This tool compares two binary or hex strings, reporting the distance, total bit length, matching bits, and the exact positions that differ.

Formula
Hamming distance = popcount(A XOR B) = number of positions where A and B differ
How this is calculated

Enter two strings of the same length. Choose the input format: binary strings use only the characters 0 and 1, while hexadecimal strings are first expanded to their 4-bit binary representation (each hex digit becomes exactly 4 bits, so a 2-digit hex value becomes 8 bits).

The calculator compares the two resulting bit strings position by position. Each position where the bits differ contributes 1 to the Hamming distance. Equivalently, the distance equals the number of set bits (the population count, or popcount) of the bitwise XOR of the two values, because XOR yields a 1 exactly where the inputs disagree. The total length is the number of bits compared, matching bits is length minus distance, and the differing positions are listed using 0-based indexing from the left.

The two strings must be the same length, otherwise the comparison is undefined and no result is shown. Inputs with characters outside the chosen alphabet are rejected. The Hamming distance is a core metric in coding theory: the minimum Hamming distance of a code determines how many bit errors it can detect and correct.

Frequently asked questions

It is the number of positions at which two equal-length strings differ. For binary data it equals the count of 1-bits in the XOR of the two values.

Hamming distance is only defined for equal-length strings because it compares bits position by position. For different lengths, use edit (Levenshtein) distance instead.

Each hexadecimal digit is expanded to 4 binary bits (for example, F becomes 1111), and the resulting bit strings are then compared as binary.

Also known as

bit difference
compare binary strings
error correcting code distance
xor distance
hamming distance

APA

TG we-Calculate Editorial Team. (2026). Hamming Distance Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/hamming-distance-calculator

Chicago

TG we-Calculate Editorial Team. "Hamming Distance Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/hamming-distance-calculator.

IEEE

TG we-Calculate Editorial Team, "Hamming Distance Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/hamming-distance-calculator

BibTeX

@misc{wecalculate_hamming_distance_calculator, title = {Hamming Distance Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/hamming-distance-calculator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?