nvm.the output i got is nearly exact which is 111 but not 110...
can you telll me why?
Code:
#include <stdio.h>
#include<stdlib.h>
#include <conio.h>
int main()
{
int a[20],b[20],c[20],d[20],i,k,g,j,p,n,s=0,t=0;
int msb;
printf("enter size of dataword\n");
scanf("%d",&n);
printf("enter dataword to be transfer bit by bit\n");
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("your input dataword is\n");
for (i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
printf("enter size of divisor\n");
scanf("%d",&g);
printf("enter divisor to be transfer bit by bit\n");
for (j=0;j<g;j++)
{
scanf("%d",&b[j]);
}
printf("your input divisor is\n");
for (j=0;j<g;j++)
{
printf("%d\n",b[j]);
}
for (i=0;i<(g-1);i++)
{
a[n+i]=0;
}
printf("the augmented dataword\n");
for (i=0;i<(g+n-1);i++)
{
printf("%d\n",a[i]);
}
printf("the resulting output of modulus is \n");
for (j=0;j<g-1;j++){
for (i=0;i<g-1;i++)
{
if (a[i] !=0)
{
a[i]^=b[j];
}
else
a[i]^=0;
}
printf("%d\n",a[i]);
}
return 0;
}
/*
for( i=0;i<g;i++)
{
c[i]= a[i];
}
for(t=0;t<(n-1);t++)
{
for(j=1;j<g;j++)
{
c[j-1]=c[j]^b[j];
c[j]=a[g+s];
}
for ( i =0;i<g;i++)
printf("%d",c[i]);
printf("\n");
s++;
}
//last loop
for(i=0;i<g;i++)
c[i]=c[i]*b[i];
//print remainder
for(i=0;i<g;i++)
printf("%d",c[i]);
/*
printf("the resulting output of modulus is \n");
for (j=0;j<g-1;j++){
for (i=0;i<g-1;i++)
{
if (a[i] !=0)
{
a[i]^=b[j];
}
else
a[i]^=0;
}
printf("%d\n",a[i]);
}
for(i=0;i<n;++i)
d[i]= a[i];
for(i=0;i<n;++i)
{
if(a[i]==0)
{
for(j=i;j<g+i;++j)
a[j] = a[j]^0;
}
else
{
a[i] = a[i]^b[0];
a[i+1]=a[i+1]^b[1];
a[i+2]=a[i+2]^b[2];
a[i+3]=a[i+3]^b[3];
}
}
*//*
printf("\n\t The CRC is :");
for(i=n;i<a;++i)
printf("%d",a[i]);
for(i=0;i<g-1;++i)
d[i]=a[i];
s=n+a;
for(i=n;i<s;i++)
c[i]=a[i];
printf("\n");
printf("\n\t The codeword is :");
for(i=0;i<a;i++)
printf("%d",c[i]);
*/