0% found this document useful (0 votes)
4K views

CRC Code in C

This document contains the source code for a program that implements CRC (Cyclic Redundancy Check) encoding. It takes in input data, converts it to binary, calculates the parity bits based on a divisor polynomial, appends the parity bits, and displays the encoded data packet. Key functions include converting to binary, appending parity bits, performing the CRC division algorithm, and displaying the encoded packet. The program takes in a data string, frame size, and divisor polynomial as input and outputs the original and encoded packets.

Uploaded by

gaurav2616146
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views

CRC Code in C

This document contains the source code for a program that implements CRC (Cyclic Redundancy Check) encoding. It takes in input data, converts it to binary, calculates the parity bits based on a divisor polynomial, appends the parity bits, and displays the encoded data packet. Key functions include converting to binary, appending parity bits, performing the CRC division algorithm, and displaying the encoded packet. The program takes in a data string, frame size, and divisor polynomial as input and outputs the original and encoded packets.

Uploaded by

gaurav2616146
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*----------------------------------------------------------------

NAME :GAURAV KHANDELWAL ROLL NO. :08BCE131


COLLAGE: NIRMA UNIVERSITY
AIM : TO IMPLEMENT CRC SENDER
-------------------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
char data[20];
char divisor[8],d_char[20];
int ans[100],ans1[100]={0},result[100]={0},frame,divisor1[8]={0};
int count=0,t=0;
void bin_conv(int s)
{
while(s!=0)
{
ans1[count]=s%2;
s/=2;
count++;
}
}
void parity_append(int a)
{
int z=0;
if(count%frame!=0)
{
z=1;
}
for(int i=0;i<count/frame+z;i++)
{
for(int j=0;j<frame;j++)
{
result[t]=ans[frame*i+j];
t++;
}
t=t+a;
}
}
void display(void)
{
for(int i=0;i<t;i++)
{
cout<<result[i];
}
}
void division(int a)
{
int z=0;
int temp[10];
if(count%frame!=0)
z=1;
for(int i=0;i<(count/frame)+z;i++)
{
for(int j=0;j<frame;j++)
{
if(j==0)
{
for(int q=0;q<a;q++)
temp[q]=result[(frame+a-1)*i+q];
}
else
{
for(int q=0;q<a-1;q++)
temp[q]=temp[q+1];
temp[q]=result[j+a-1+(frame+a-1)*i];
}
if(temp[0]==1)
{
for(int k=0;k<a;k++)
temp[k]=temp[k]^divisor1[k];
}
}
for(int l=0;l<a-1;l++)
result[(i*(a-1))+((i+1)*frame)+l]=temp[l+1];
}
}
void main()
{
clrscr();
cout<<"enter the data:";
gets(data);
cout<<"enter the frame size:";
cin>>frame;
cout<<"enter the error handler not more then 7:";
gets(divisor);
int i=0;
while(divisor[i]!='\0')
{
if(divisor[i]=='1')
divisor1[i]=1;
else
divisor1[i]=0;
i++;
}
int j=0,d,k;
while(data[j]!='\0')
{
d=toascii(data[j]);
d_char[j]=data[j];
bin_conv(d);
for(k=0;k<7;k++)
ans[7*j+k]=ans1[count-k-1];
j++;
}
parity_append(i-1);
cout<<"packet without parity:";
display();
division(i);
cout<<"\n";
cout<<"now packet with parit:";
display();
getch();
}
/*
If you want any program in c or c++ then mail me. I will provide you that progr
am.
For program mail me [email protected],[email protected]
THANK YOU.
*/

You might also like