Cyclic redundancy check program using c
#include<stdio.h>
void main()
{
int Data[100],n,Div[20],d,i,j,t[20],t1,k;
printf("\n enter how many bit in data and div");
scanf("%d %d",&n,&d);
int p[20];
printf("\n enter data bit");
for(i=0;i<n;i++)
{
scanf("%d",&Data[i]);
}
printf("i==%d",i);
for(j=i;j<n+d-1;j++)
{
Data[j]=0;
}
printf("\n enter div bit");
for(i=0;i<d;i++)
{
scanf("%d",&Div[i]);
p[i]=0;
}
for(i=0;i<n+d-1;i++)
{
printf("\t %d",Data[i]);
}
t1=n+d-1;
i=0;
while(i<t1)
{
j=0;
while(p[j]!=1&&j<d)
{
j++;
}
k=0;
for(k;j<d;k++)
{
t[k]=p[j];
j++;
}
while(k<d)
{
t[k]=Data[i];
i++;
k++;
}
printf("\n");
for(k=0;k<d;k++)
{
p[k]=(t[k]==Div[k])?0:1;
printf("\t %d",p[k]);
}
}
printf("\n \n remainder is");
for(k=0;k<d,k++)
{
printf("\t %d",p[k]);
}
k=1;
for(i=n;i<n+d-1;i++)
{
Data[i]=p[k];
k++;
}
printf("\n reciever side");
for(i=0;i<n+d-1;i++)
{
printf("\t %d",Data[i]);
}
}
void main()
{
int Data[100],n,Div[20],d,i,j,t[20],t1,k;
printf("\n enter how many bit in data and div");
scanf("%d %d",&n,&d);
int p[20];
printf("\n enter data bit");
for(i=0;i<n;i++)
{
scanf("%d",&Data[i]);
}
printf("i==%d",i);
for(j=i;j<n+d-1;j++)
{
Data[j]=0;
}
printf("\n enter div bit");
for(i=0;i<d;i++)
{
scanf("%d",&Div[i]);
p[i]=0;
}
for(i=0;i<n+d-1;i++)
{
printf("\t %d",Data[i]);
}
t1=n+d-1;
i=0;
while(i<t1)
{
j=0;
while(p[j]!=1&&j<d)
{
j++;
}
k=0;
for(k;j<d;k++)
{
t[k]=p[j];
j++;
}
while(k<d)
{
t[k]=Data[i];
i++;
k++;
}
printf("\n");
for(k=0;k<d;k++)
{
p[k]=(t[k]==Div[k])?0:1;
printf("\t %d",p[k]);
}
}
printf("\n \n remainder is");
for(k=0;k<d,k++)
{
printf("\t %d",p[k]);
}
k=1;
for(i=n;i<n+d-1;i++)
{
Data[i]=p[k];
k++;
}
printf("\n reciever side");
for(i=0;i<n+d-1;i++)
{
printf("\t %d",Data[i]);
}
}
Comments
Post a Comment