Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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')

Question 2: Given an 8 bits data store in main memory as 01001100. Compute the Hamming code that for this data. Show the computation of each check bit clearly in your steps of calculation using the table below. Position12 11 9 8 76 5 4 3 2 Position number Data bit C1 (--1) C2 (1-) C4 (-1-) C8 (1 H. Code Question 2: Given an 8 bits data store in main memory as 01001100. Compute the Hamming code that for this data. Show the computation of each check bit clearly in your steps of calculation using the table below. Position12 11 9 8 76 5 4 3 2 Position number Data bit C1 (--1) C2 (1-) C4 (-1-) C8 (1 H. Code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago

Question

d. What language(s) did they speak?

Answered: 1 week ago

Question

e. What difficulties did they encounter?

Answered: 1 week ago