In: Computer Science
5. Implement 2-D error detection mechanism using even parity check. Given a data bit to be send, perform the even parity check for the data to be send. Append the parity bit at the end of that data. At the receiver end, the receiver has to check for errors in transmission
Please code in C language.
//Dear Student, I have spent a lot of time on it, so if you got something from it, then give an upvote. Thank you
#include <stdio.h>
int main()
{
int parity(int a[],int b);
int n,i;
printf("Enter the length of the message 4-bit/8-bit/16-bit:");
scanf("%d",&n);
int send[n],rec[n],s,r;
printf("Enter the senders message:");
for(i=0;i<n;i++)
scanf("%d",&send[i]);
s=parity(send,n);
printf("Enter the receivers message:");
for(i=0;i<n;i++)
scanf("%d",&rec[i]);
r=parity(rec,n);
printf("Parity bit for sender:%d\n",s);
printf("Parity bit for receiver:%d\n",r);
if(s==r){
printf("No error");
}
else{
printf("Error");
}return 0;
}
int parity(int p[],int n)
{
int i=n/2;
int a[i],b[i],c[i];
int j,k=0;
for(j=0;j<n/2;j++)
{
a[j]=p[j];
}
for(j=i;j<n;j++)
{
b[k]=p[j];k++;
}
for(i=0;i<n/2;i++)
{
if(a[i]==b[i])
{
c[i]=0;
}
else
{
c[i]=1;
}
}
int count=0;
for(i=0;i<n/2;i++)
{
if(c[i]==1)count++;
}
if(count%2==0)
{
return 0;
}
else
{
return 1;
}
}
The output of above code will display as: