Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 views2 pages

CRC Program

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

CRC Program

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Implement on a dataset of characters using CRC polynomials-CRC 12 and CRC 16.

Source Code:

#include<stdio.h>

void division(int temp[],int gen[],int n,int r)


{
for(int i=0;i<n;i++)
{
if (gen[0]==temp[i])
{
for(int j=0,k=i;j<r+1;j++,k++)
{
temp[k]=temp[k]^gen[j];
}
}

}
int main()
{
int n,r,message[50],gen[50],temp[50];

printf("Enter the number of frame bits : ");


scanf("%d",&n);
printf("Enter the frame : ");
for(int i=0;i<n;i++)
scanf("%d",&message[i]);
printf("Enter the number of generator bits : ");
scanf("%d",&r);

printf("Enter the generator : ");


for(int i=0;i<r;i++)
scanf("%d",&gen[i]);
r--;
for(int i=0;i<r;i++)
message[n+i] = 0;
for(int i=0;i<n+r;i++)
temp[i] = message[i];
division(temp,gen,n,r);
printf("CRC : ");
for(int i=0;i<r;i++)
{
printf("%d ",temp[n+i]);
message[n+i] = temp[n+i];
}
printf("\nTransmitted Message : ");
for(int i=0;i<n+r;i++)
printf("%d ",message[i]);
printf("\nDecoding ");
for(int i=0;i<n+r;i++)
temp[i] = message[i];
division(temp,gen,n,r);
for(int i=0;i<r;i++)
{
if(temp[n+i])
{
printf("Error detected in received message.");
return 0;
}

}
printf("\nNo error in received Message.");
printf("\nAfter decoding crc is ");
for(int i=0;i<r;i++)
{
printf("%d ",temp[n+i]);
}
printf("\nReceived Message : ");
for(int i=0;i<n;i++)
printf("%d ",message[i]);
return 0;
}

EXECUTION:

Enter the number of frame bits : 4

Enter the frame : 1 0 0 1

Enter the number of generator bits : 4

Enter the generator : 1 0 1 1

CRC : 1 1 0

Transmitted Message : 1 0 0 1 1 1 0

Decoding

No error in received Message.

After decoding crc is 0 0 0

Received Message : 1 0 0 1

Executed Successfully.

You might also like