What is the Hamming distance between 1101 and 110, if 110 is left-padded as…
2018
What is the Hamming distance between 1101 and 110, if 110 is left-padded as 0110?
Answer: B. 3 — The Hamming distance between two binary strings of equal length is the number of bit positions at which their corresponding bits differ. Before comparing two…
- A.
2
- B.
3
- C.
4
- D.
0
Attempted by 1002 students.
Show answer & explanation
Correct answer: B
The Hamming distance between two binary strings of equal length is the number of bit positions at which their corresponding bits differ. Before comparing two strings of different lengths, the shorter one must first be padded on the left with leading zeros so both have the same length.
Pad the shorter string 110 with a leading zero to match the length of 1101, giving 0110.
Compare the two four-bit strings, 1101 and 0110, bit by bit at each of the four positions.
Positions 1, 3, and 4 have different bits, while position 2 has the same bit in both strings.
Position | 1101 | 0110 | Match |
|---|---|---|---|
1 | 1 | 0 | Differ |
2 | 1 | 1 | Same |
3 | 0 | 1 | Differ |
4 | 1 | 0 | Differ |
As an independent check, take the bitwise XOR of the two strings: 1101 XOR 0110 = 1011. The number of 1s in this XOR result equals the Hamming distance, and 1011 has three 1s, matching the position-by-position count above.
Since exactly three of the four bit positions differ, the Hamming distance between 1101 and (padded) 0110 is 3.