Advertisement

Hamming distance calculator

Count differing bit positions in two equal-length binary messages or two unsigned 16-bit decimal integers, with the XOR mask shown for checking.

Calculator

Hamming distance
2.000000
Differing-bit mask
0011
First binary word
1010
Second binary word
1001

Advertisement

How this calculator works

Compare corresponding bits and count the mismatches. Binary mode preserves leading zeros and requires the same length. Decimal mode represents both non-negative integers as 16-bit binary words before comparing. Distance measures substitutions at fixed positions, not insertions or deletions.

Formula

d(a,b) = count of 1 bits in a XOR b.

Worked example

1010 and 1001 differ in the last two positions, so their distance is 2. Decimal 0 and 65535 differ in every one of 16 bits.

Advertisement

Frequently asked questions

Do leading zeros matter?

They define the binary word length. Both binary messages must be written to the same width.

Is this edit distance?

No. Hamming distance counts substitutions between equal-length words; edit distance can include insertions and deletions.

Can I enter negative decimal values?

No. This tool uses unsigned 16-bit words. Two-complement signed values need an explicitly chosen representation.

Sources

Advertisement