A question asks: find the hamming distance of the following code:
11111
10101
01010
11100
00011
11001
The answer is 2. How does this work? I thought hamming distance is only between two strings?
Since the two codewords differ in 6 bit positions as indicated by bold letter bits, the hamming distance is 6.
The Hamming distance d(10101, 11110) is 3 because 10101 ⊕ 11110 is 01011 (three 1s).
Answer. Now, 10101010 ⊕ 10010010 = 111000. Since there are three zeroes, the hamming distance is 1 + 1 + 1 = 3.
The correct answer should be 3. In information technology studies, the Hamming distance in between two strings which are of equal length is defined by the number of positions at which their corresponding symbols are different.
The Hamming distance of a code is defined as the minimum distance between any 2 codewords. So, in your case, finding the Hamming distance between any 2 of the listed codewords, no one is less than 2.
Here is some Python-code to find it automatically:
code = [
(0,0,0,0,0,0),
(0,0,1,0,0,1),
(0,1,0,0,1,0),
(0,1,1,0,1,1),
(1,0,0,1,0,0),
(1,0,1,1,0,1),
(1,1,0,1,1,0),
(1,1,1,1,1,1)]
def hammingDistance(a, b):
distance = 0
for i in xrange(len(a)):
distance += a[i]^b[i]
return distance
def minHammingDistance(code):
minHammingDistance = len(code[0])
for a in code:
for b in code:
if a != b:
tmp = hammingDistance(a, b)
if tmp < minHammingDistance:
minHammingDistance = tmp
return minHammingDistance
print("min Hamming distance: %i" % minHammingDistance(code))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With