Solution CRC
Solution CRC
(PCC-CS-692)
Test Case 1:
Input:
Dataword: 100100
Coefficients of generator polynomial: 1101
Output:
Updated divident: 100100000
The codeword is: 100100001
Test Case 2:
Input:
Dataword : 1010001101
Coefficients of generator polynomial: 110101
Output:
Updated divident: 101000110100000
The codeword is: 101000110101110
#include<stdio.h>
#include<string.h>
void main()
{
char data[50],divisor[10],data1[50];
int dl,divl,i,j;
printf("\nEnter the input data: ");
gets(data);
printf("\nEnter coefficients of generator polynomial: ");
gets(divisor);
dl=strlen(data);
divl=strlen(divisor);
for(i=0;i<divl-1;i++) //no of 0's that have to add with divident
data[dl+i]='0';
data[dl+i]='\0';
printf("\nUpdated divident: %s",data);
strcpy(data1,data);
for(i=0;i<dl;i++)
{
if(data1[i]=='1')
{
for(j=0;j<divl;j++)
{
if(data1[i+j]==divisor[j])
data1[i+j]='0';
else
data1[i+j]='1';
}
}
}
for(i=dl;i<dl+(divl-1);i++)
data[i]=data1[i];
printf("\nThe codeword is: %s",data);
}
Test Case 1:
Input:
Codeword:101000110101110
Coefficients of generator polynomial:110101
Output:
Original data receive
Actual data: 1 0 1 0 0 0 1 1 0 1
Test Case 2:
Input:
Codeword: 100100001
Coefficients of generator polynomial: 1101
Output: