Compare bit positions, not numeric values
Treat each input as a sequence of aligned bit positions. The first bit is compared with the first, the second with the second, and so on. A position contributes one when the bits differ and zero when they match. The total is a nonnegative integer from zero through the string length, with zero meaning the two entered strings are identical at every position.
Use equal-width binary strings
Both inputs must have the same length and contain only zeroes and ones. A leading zero is significant for alignment and should be retained when the code uses a fixed width. For example, a four-bit word and a three-bit word cannot be compared position by position without an explicit padding rule; silently dropping a zero can produce a different distance.
Count mismatches one position at a time
The calculation is d(x,y)=Σ 1[xᵢ≠yᵢ], over all positions i. This is the Hamming distance: it counts substitutions needed to turn one string into the other when insertions and deletions are not allowed. NIST’s Dictionary of Algorithms and Data Structures describes it as the number of differing bit positions between binary strings.
Leading zeroes preserve the comparison width
Do not confuse Hamming distance with the difference between the decimal values represented by the strings. Two numbers can be numerically close and differ in several bit positions, or be far apart numerically while differing in only one bit. Distance depends on the chosen representation and width, not just the integer values.
Interpret the distance in context
A distance can help describe code separation. If a code’s minimum distance is known, coding theory can derive bounds on detectable or correctable errors, but this calculator does not analyze a codebook or prove those guarantees. It compares only the two supplied strings and returns a mismatch count.
Fixed-width formatting is part of the comparison contract. If a device transmits eight bits but a log strips leading zeroes, restore the documented width before comparing values. Conversely, do not pad arbitrary strings merely to satisfy the calculator unless the system specification says the missing positions are leading zeroes. Make that decision explicit so a distance result can be reproduced.
In error-control coding, a codebook’s minimum pairwise Hamming distance—not the distance between one arbitrary pair—supports detection and correction bounds. A minimum distance d can detect up to d−1 bit errors and uniquely correct up to floor((d−1)/2) under the usual assumptions. The two-word calculator result is not enough to claim either property without examining every valid codeword and the decoding rule.
Worked examples
Each string is compared at equal positions; zero-padding is not added unless already shown in the input.
Two seven-bit words
Inputs: First = 1011101; second = 1001001.
Calculation: Compare positions: 1=1, 0=0, 1≠0, 1=1, 1≠0, 0=0, 1=1; distance = 2 differing bits.
Two of the seven aligned bit positions differ.
Two eight-bit words
Inputs: First = 11111111; second = 11011001.
Calculation: Mismatches occur at positions 3, 6, and 7; Hamming distance = 3 bits.
Three substitutions would make the first bit string match the second.
Limits of a raw mismatch count
In data quality work, equal-width inputs can represent two sensor words, register states, IDs, or encoded values. Before comparing them, verify that both use the same bit ordering and that they were captured at the same point in a pipeline. A bit-order reversal or truncation can look like a meaningful change even when it is only a formatting mismatch.
This measure treats each bit mismatch equally and ignores position importance, insertion/deletion edits, and semantic meaning. For unequal-length text, use an edit distance; for numeric closeness, use an arithmetic difference; for code performance, evaluate the entire code structure. The simple count is valuable precisely because it answers one narrow, representation-level question.