-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRC.cpp
More file actions
77 lines (76 loc) · 1.42 KB
/
CRC.cpp
File metadata and controls
77 lines (76 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//Cyclic redundancy check (CRC)
#include<stdio.h>
main()
{
int da[20],di[20],te[20],tem[20],l,s[20];
int i,j,m,n,data,div,t,k,e;
printf("\nEnter the total bit of data and divisor :");
scanf("%d %d",&data,&div);
m=data+div-1;
printf("\nEnter the data:");
for(i=0;i<data;i++)
{
scanf("%d",&da[i]);
te[i]=da[i];
s[i]=da[i];
}
for(i=data;i<m;i++)
te[i]=0;
printf("\nEnter the divisor:");
for(i=0;i<div;i++)
scanf("%d",&di[i]);
l=div;t=0;
k=0;
for(i=0;i<data;i++)
{
e=0;t=0;
for(j=1;j<div;j++)
{
if(((da[j]==1)&&(di[j]==1))||((da[j]==0)&&(di[j]==0)))
{
tem[j-1]=0;
if(e!=1)
{
k=k+1;
t=t+1;
i=i+1;
}
}
else
{
tem[j-1]=1;
e=1;
}
}
j=0;
for(e=t;e<div-1;e++)
{
da[j]=tem[e];
j++;
}
for(j=j;j<div;j++)
{
if(l>=data+1)
{
da[j]=0;
}
else
{
da[j]=te[l];
l=l+1;
}
}
}
printf("\n The CRC BITS are :");
for(i=0;i<div-1;i++)
{
s[i+data]=tem[i];
printf(" %d",tem[i]);
}
printf("\nThe Sent bits are:");
for(i=0;i<m;i++)
{
printf(" %d",s[i]);
}
return 0;
}