CRC in c (cyclic redundancy check)
CRC
crc is error detecting code,it is commonly use in digital network.
Understanding for:
![](https://ecomputernotes.com/images/CRC-decoded-Binary-division.jpg)
cyclic redundancy check:
#include<stdio.h>
void main()
{
int i,j,n,m,data[100],data1[100],div[100],rem[100],quo[100],temp,cnt=0;
int k=1;
printf("enter number of element in data\n");
scanf("%d",&n);
printf("enter number of element in divisor\n");
scanf("%d",&m);
printf("enter elements of data:\n ");
for(i=0;i<n;i++)
{
scanf("%d",&data[i]);
}
printf("enter elements of divisor:\n ");
for(i=0;i<m;i++)
{
scanf("%d",&div[i]);
}
for(i=0;i<n;i++)
{
data1[i]=data[i];
}
for(i=n;i<n+m-1;i++)
{
data1[i]=0;
}
for(i=0;i<n;i++)
{
temp=i;
if(data1[i]==1)
{
for(j=0;j<m;j++)
{
if(data1[temp]==div[j])
{
data1[temp]=0;
rem[j]=0;
}
else
{
data1[temp]=1;
rem[j]=1;
}
temp=temp+1;
}
quo[i]=1;
}
else
{
quo[i]=0;
}
}
for(i=n;i<n+m-1;i++)
{
data[i]=rem[k];
k=k+1;
}
for(i=0;i<n;i++)
{
temp=i;
if(data[i]==1)
{
for(j=0;j<m;j++)
{
if(data[temp]==div[j])
{
data[temp]=0;
rem[j]=0;
}
else
{
data[temp]=1;
rem[j]=1;
}
temp=temp+1;
}
quo[i]=1;
}
else
{
quo[i]=0;
}
}
for(i=0;i<m;i++)
{
if(rem[i]==0)
{
cnt=cnt+1;
}
}
if(cnt==m)
{
printf("\nerror not detected\n");
}
else
{
printf("error detected");
}
}
output:
crc is error detecting code,it is commonly use in digital network.
Understanding for:
![](https://ecomputernotes.com/images/CRC-decoded-Binary-division.jpg)
cyclic redundancy check:
Parity method detects only odd number of errors.to overcome this weakness polynomial code error detection method is used.polynomial codes involve generating parity check bits in form of CRC. Therefore polynomial also called CRC.
👉coding:#include<stdio.h>
void main()
{
int i,j,n,m,data[100],data1[100],div[100],rem[100],quo[100],temp,cnt=0;
int k=1;
printf("enter number of element in data\n");
scanf("%d",&n);
printf("enter number of element in divisor\n");
scanf("%d",&m);
printf("enter elements of data:\n ");
for(i=0;i<n;i++)
{
scanf("%d",&data[i]);
}
printf("enter elements of divisor:\n ");
for(i=0;i<m;i++)
{
scanf("%d",&div[i]);
}
for(i=0;i<n;i++)
{
data1[i]=data[i];
}
for(i=n;i<n+m-1;i++)
{
data1[i]=0;
}
for(i=0;i<n;i++)
{
temp=i;
if(data1[i]==1)
{
for(j=0;j<m;j++)
{
if(data1[temp]==div[j])
{
data1[temp]=0;
rem[j]=0;
}
else
{
data1[temp]=1;
rem[j]=1;
}
temp=temp+1;
}
quo[i]=1;
}
else
{
quo[i]=0;
}
}
for(i=n;i<n+m-1;i++)
{
data[i]=rem[k];
k=k+1;
}
for(i=0;i<n;i++)
{
temp=i;
if(data[i]==1)
{
for(j=0;j<m;j++)
{
if(data[temp]==div[j])
{
data[temp]=0;
rem[j]=0;
}
else
{
data[temp]=1;
rem[j]=1;
}
temp=temp+1;
}
quo[i]=1;
}
else
{
quo[i]=0;
}
}
for(i=0;i<m;i++)
{
if(rem[i]==0)
{
cnt=cnt+1;
}
}
if(cnt==m)
{
printf("\nerror not detected\n");
}
else
{
printf("error detected");
}
}
output:
0 comments: