SHARE
TWEET

Python Hamming Code full

naeem043 Apr 11th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top