























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Network Security and Data Communication Lab work assignment to find new secure ways to improve data protection.
Typology: Assignments
1 / 31
This page cannot be seen from the preview
Don't miss anything!
Q1. Code a C Program to test the following case, Assuming that your error detection method is following even parity, find the parity bit for each of the following data units. Code: #include <stdio.h> int main(){ int n,d,e=0; printf("Enter the binary number: "); scanf("%d",&n); while (n){ d=n%10; if (d==1){ e+=1; } n=n/10; }
scanf("%s",d); if(strlen(a)==strlen(b)&&strlen(b)==strlen(c)&&strlen(c)= =strlen(d)){ length = strlen(a); char carry='0'; for (j=0;j<3;j++) { for(i=length-1;i>=0;i--) { if(a[i]=='0' && b[i]=='0' && carry=='0') { sum[i]='0'; carry='0'; } else if(a[i]=='0' && b[i]=='0' && carry=='1') { sum[i]='1'; carry='0'; }
else if(a[i]=='0' && b[i]=='1' && carry=='0') { sum[i]='1'; carry='0'; } else if(a[i]=='0' && b[i]=='1' && carry=='1') { sum[i]='0'; carry='1'; } else if(a[i]=='1' && b[i]=='0' && carry=='0') { sum[i]='1'; carry='0'; } else if(a[i]=='1' && b[i]=='0' && carry=='1') { sum[i]='0'; carry='1';
a[i]=c[i]; } for (i=0;i<length;i++){ b[i]=d[i]; } } if (j==1){ for (i=0;i<length;i++){ sumcd[i]=sum[i]; } for (i=0;i<length;i++){ a[i]=sumab[i]; } for (i=0;i<length;i++){ b[i]=sumcd[i]; } } if (j==2){
break; } } for(i=0;i<length;i++) { if(sum[i]=='0') complement[i]='1'; else complement[i]='0'; } if(carry=='1') carry='0'; else carry='1'; printf("\nChecksum=%c%s",carry,complement); }else { printf("\nWrong input strings"); } }
char sum[20], sumab[20], sumcd[20], complement[20], sum1[20], complement1[20]; int i,length,j,x,y,w,z; printf("Enter first binary number \n"); scanf("%s",a); printf("Enter second binary number \n"); scanf("%s",b); printf("Enter third binary number \n"); scanf("%s",c); printf("Enter fourth binary number \n"); scanf("%s",d); if(strlen(a)==strlen(b)&&strlen(b)==strlen(c)&&strlen(c)= =strlen(d)){ length = strlen(a); char carry='0'; for (j=0;j<3;j++) { for(i=length-1;i>=0;i--)
if(a[i]=='0' && b[i]=='0' && carry=='0') { sum[i]='0'; carry='0'; } else if(a[i]=='0' && b[i]=='0' && carry=='1') { sum[i]='1'; carry='0'; } else if(a[i]=='0' && b[i]=='1' && carry=='0') { sum[i]='1'; carry='0'; } else if(a[i]=='0' && b[i]=='1' && carry=='1') { sum[i]='0';
sum[i]='1'; carry='1'; } else break; } if (j==0){ for (i=0;i<length;i++){ sumab[i]=sum[i]; } for (i=0;i<length;i++){ a[i]=c[i]; } for (i=0;i<length;i++){ b[i]=d[i]; } } if (j==1){ for (i=0;i<length;i++){
sumcd[i]=sum[i]; } for (i=0;i<length;i++){ a[i]=sumab[i]; } for (i=0;i<length;i++){ b[i]=sumcd[i]; } } if (j==2){ break; } } for(i=0;i<length;i++) { if(sum[i]=='0') complement[i]='1'; else
else if(sum[i]=='0' && complement[i]=='1' && carry=='0') { sum1[i]='1'; carry='0'; } else if(sum[i]=='0' && complement[i]=='1' && carry=='1') { sum1[i]='0'; carry='1'; } else if(sum[i]=='1' && complement[i]=='0' && carry=='0') { sum1[i]='1'; carry='0'; } else if(sum[i]=='1' && complement[i]=='0' && carry=='1') { sum1[i]='0'; carry='1';
else if(sum[i]=='1' && complement[i]=='1' && carry=='0') { sum1[i]='0'; carry='1'; } else if(sum[i]=='1' && complement[i]=='1' && carry=='1') { sum1[i]='1'; carry='1'; } else break; } for(i=0;i<length;i++) { if(sum1[i]=='0') complement1[i]='1'; else