Question
Can someone modify these codes , instead of showing the output str8 away , it actually shows the step by step on how to get
Can someone modify these codes , instead of showing the output str8 away , it actually shows the step by step on how to get it . Something like this. I need it step by step from generating hamming code to error detection and then error correction. Below the image are codes in python
option=int(input('Press 1 for generating hamming code Press 2 for finding error in hamming code \t Enter your choice:-- '))
if(option==1): # GENERATE HAMMING CODE print('Please enter a maximum of 8 data bits') d=input() data=list(d) data.reverse() c,ch,j,r,h=0,0,0,0,[]
while ((len(d)+r+1)>(pow(2,r))): r=r+1
for i in range(0,(r+len(data))): p=(2**c)
if(p==(i+1)): h.append(0) c=c+1
else: h.append(int(data[j])) j=j+1
for parity in range(0,(len(h))): ph=(2**ch) if(ph==(parity+1)): startIndex=ph-1 i=startIndex toXor=[]
while(i for z in range(1,len(toXor)): h[startIndex]=h[startIndex]^toXor[z] ch+=1 h.reverse() print('Hamming code generated would be:- ', end="") print(int(''.join(map(str, h)))) elif(option==2): # DETECT ERROR IN RECEIVED HAMMING CODE print('Enter the hamming code received') d=input() data=list(d) data.reverse() c,ch,j,r,error,h,parity_list,h_copy=0,0,0,0,0,[],[],[] for k in range(0,len(data)): p=(2**c) h.append(int(data[k])) h_copy.append(data[k]) if(p==(k+1)): c=c+1 for parity in range(0,(len(h))): ph=(2**ch) if(ph==(parity+1)): startIndex=ph-1 i=startIndex toXor=[] while(i for z in range(1,len(toXor)): h[startIndex]=h[startIndex]^toXor[z] parity_list.append(h[parity]) ch+=1 parity_list.reverse() error=sum(int(parity_list) * (2 ** i) for i, parity_list in enumerate(parity_list[::-1])) if((error)==0): print('There is no error in the hamming code received') elif((error)>=len(h_copy)): print('Error cannot be detected') else: print('Error is in',error,'bit') if(h_copy[error-1]=='0'): h_copy[error-1]='1' elif(h_copy[error-1]=='1'): h_copy[error-1]='0' print('After correction hamming code is:- ') h_copy.reverse() print(int(''.join(map(str, h_copy)))) else: print('Option entered does not exist')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started