Source Code for CRC(Cyclic Redundancy Check)


This is a source code for cyclic redundancy check. This helps us to check whether there is error in the transmitted bit.Error in the transmitted bit can be verified by CRC.

C Programming Source Code for CRC(Cyclic Redundancy Check)


==========================================
C Programming Source Code for CRC(Cyclic Redundancy Check)
==========================================

#include"stdio.h"
#include"math.h"
#include"conio.h"
int decm1(int,int *);
int decm(int,int *);
int rx[20];
void main()
{
int n,num,gx[20],dx[30],fx[20],i;
int app,k,m,no,val,j;
clrscr();
printf("Enter length of dx: ");
scanf("%d",&m);
printf("Enter the value of dx: "); /*INFORMATION TO BE TRANSMITTED*/
for(i=0;i {
scanf("%d",&dx[i]);
}
printf("\nEnter length of gx: "); /*LENGTH OF GENERATOR*/
scanf("%d",&n);
printf("\nEnter the value of gx: "); /*GENERATOR POLYNOMIAL*/
for(i=0;i {
scanf("%d",&gx[i]);
}
app=n-1;
k=m+app;
for(i=m;i dx[i]=0;
printf("\nMODIFIED VALUE OF BITS TO BE TRANSMITTED: ");
for(i=0;i printf("%d",dx[i]);
no=k-n;
for(i=0;i {
if (gx[i]==dx[i])
rx[i]=0;
else
rx[i]=1;
}
while(no!=0)
{
rx[n]=dx[i];
if(rx[1]==0)
{
for(j=0;j fx[j]=0;
for(j=0;j {
if (fx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j printf("%d",rx[j]);
}
else
{
for(j=0;j {
if (gx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j printf("%d",rx[j]);
}
no--;
i++;
}
printf("CRC BITS");
num=n;
for(i=k-1;i>0;i--)
{
num--;
if(num>0)
{
if(dx[i]==rx[num])
dx[i]=0;
else
dx[i]=1;
}
}
printf("\nTranssmitted bits: ");
for(i=0;i printf("%d",dx[i]); /* ACTUAL BITS TRANSMITTED */

/*DIVIDING TRANSMITTED BIT BY GENERATOR BITS*/
for(i=0;i {
if (gx[i]==dx[i])
rx[i]=0;
else
rx[i]=1;
}
for(i=0;i printf("%d",rx[i]);
no=k-n;
while(no!=0)
{
rx[n]=dx[i];
if(rx[1]==0)
{
for(j=0;j fx[j]=0;
for(j=0;j {
if (fx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j printf("%d",rx[j]);
}
else
{
for(j=0;j {
if (gx[j]==rx[j+1])
rx[j]=0;
else
rx[j]=1;
}
printf("\n");
for(j=0;j printf("%d",rx[j]);
}
no--;
i++;
}
printf("\nremainder bits:");
for(i=0;i printf("%d",rx[i]);
for(i=0;i {
if (rx[i]==0)
val=0;
else
val=1;
}
if(val==0)
printf("\n NO ERROR IN TRANSMISSION:");
else
printf("\n ERROR IN TRANSMISSION: ");
getch();
}


Related Articles

More articles: C Programming Source Code Cyclic Redundancy Check Computer

Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: