Hamming Code
Hamming Code
# hamming code
def calcRedundantBits(m):
for i in range(m):
if(2**i >= m + i + 1):
return i
# String Concatenation
# (0 to n - 2^r) + parity bit + (n - 2^r + 1 to n)
arr = arr[:n-(2**i)] + str(val) + arr[n-(2**i)+1:]
return arr
def detectError(arr, nr):
n = len(arr)
res = 0
# Data to be transferred
print("Data transferred is " + arr)
arr = '11101001110'
print("Error Data is " + arr)
correction = detectError(arr, r)
if(correction==0):
print("There is no error in the received message.")
else:
print("The position of error is ",len(arr)-correction+1,"from the left")
print()
OUTPUT: