Seminar 14


In [16]:
def get_Hamming_weight(binary_number):
    count = 0
    for no in map(int, str(binary_number)):
        if no:
            count += 1
    return count

print('Hamming weight of ' + str(1001) + ' is: ' + str(get_Hamming_weight(1001)))

def get_Hamming_distance(binary_a, binary_b):
    count = 0
    i = 0
    for i in range(len(str(binary_a))):
        if str(binary_a)[i] != str(binary_b)[i]:
            count += 1
    return count

print('Hamming distance of ' + str(1001) + ' and ' + str(1110) + ' is: ' + str(get_Hamming_distance(1001, 1110)))


Hamming weight of 1001 is: 2
Hamming distance of 1001 and 1110 is: 3

In [ ]:
'''
Sure is Hw(u) ? (bytes of 1 of u) - seems like it ...
or is it Hd(v, u) - v being the closest word in C for u (with how many bytes does u modify v)

detection threshold for an error u
Hw(u) < d(C)-1

correction threshold for an error u
Hw(u) < \floor{ \frac{d(C)-1}{2} }

'''