Hamming Distance Calculator
Compare two equal-length binary or hexadecimal strings and count the positions where their bits differ.
Input format
Number of positions where the bits differ
- 1
Total bit positions
7 - 2
Matching positions
7 − 2 = 5 - 3
Hamming distance
7 − 5 = 2Number of positions where the bits differ — equivalent to popcount(A XOR B).
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
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
TG we-Calculate Editorial Team. (2026). Hamming Distance Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/hamming-distance-calculator
TG we-Calculate Editorial Team. "Hamming Distance Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/hamming-distance-calculator.
TG we-Calculate Editorial Team, "Hamming Distance Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/hamming-distance-calculator
@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?
