Advertisement
naeem043

Python Hamming Code full

Apr 11th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. data = input('Enter the data bit: ')
  2. p1 = int(data[3])^int(data[2])^int(data[0])
  3. p2 = int(data[3])^int(data[1])^int(data[0])
  4. p3 = int(data[2])^int(data[1])^int(data[0])
  5. codeword = data[0]+data[1]+data[2]+str(p3)+data[3]+str(p2)+str(p1)
  6. print("The parity bit is: ",p1,p2,p3 , "The codeword is: ", codeword)
  7. receive_data = input('Enter the receive data bit: ')
  8. count = 0
  9. if len(receive_data) == len(codeword):
  10.     for i in codeword:
  11.         if i != receive_data[count]:
  12.             print('The error in position: ',count+1)
  13.             break;
  14.         count += 1
  15. else:
  16.     print('Receive data bit size and send data bit size is not same')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement