You are on page 1of 2

/* CRC 12 */

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char f[45],c[2];
char g[15],t[50];
int l,i,j,k,m;
clrscr();
printf("Enter 13 bit input string\n");
gets(f);
//strcpy(g,"1100000001111");
printf("Enter 13-bit Generator Polynomial\n");
gets(g);
i=strlen(g);
l=strlen(f);
for(k=1;k<i;k++,l++)
f[l]='0';
f[l]='\0';
l=strlen(g)-1;
for(i=0;i<=l;i++)
t[i]=f[i];
t[i]='\0';
for(;l<strlen(f);)
{
for(i=0;i<strlen(t);i++)
{
itoa(t[i]^g[i],c,10);
t[i]=c[0];
}
//printf("\n Remainder of XOR operation is: %s",t); // getch();
for(i=0;t[i]=='0';i++);
for(j=i,k=0;t[j]!='\0';j++,k++)
t[k]=t[j];
t[k]='\0';
for(j=1,m=l+1;j<=i;j++,m++,k++)
t[k]=f[m];
t[k]='\0';
//printf("\nAfter removing zerso is %s",t);
l=m-1;
}
printf(" Remainder is %s",t);
// getch();

return 0;
}

You might also like