-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHamming Code.c
More file actions
61 lines (47 loc) · 1.16 KB
/
Hamming Code.c
File metadata and controls
61 lines (47 loc) · 1.16 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
//Hamming code
#include<stdio.h>
int main()
{
int data[4];
int cw[7];
int rev[7];
int i,c,c1,c2,c3;
printf("Enter the 4 bit dataword:\n");
for(i=1;i<=4;i++)
scanf("%d",&data[i]);
cw[3]=data[1];
cw[5]=data[2];
cw[6]=data[3];
cw[7]=data[4];
cw[1]=(cw[3] ^ cw[5] ^ cw[7]);
cw[2]=(cw[3] ^ cw[6] ^ cw[7]);
cw[4]=(cw[5] ^ cw[6] ^ cw[7]);
printf("\nGenerated codeword is:\n");
for(i=1;i<=7;i++)
printf("%d",cw[i]);
printf("\nEnter the reciver recived data:\n");
for(i=1;i<=7;i++)
scanf("%d",&rev[i]);
printf("\n");
c1=(rev[1] ^ rev[3] ^ rev[5] ^ rev[7]);
c2=(rev[2] ^ rev[3] ^ rev[6] ^ rev[7]);
c3=(rev[4] ^ rev[5] ^ rev[6] ^ rev[7]);
c=c1*1+c2*2+c3*4;
if(c==0)
printf("\nNo error dected in transmission.....");
else
{
printf("\nError found in Position: %d\n",c);
printf("\nData generated bt Seneder: ");
for(i=1;i<=7;i++)
printf("%d",cw[i]);
printf("\nData recived on reciver side: ");
for(i=1;i<=7;i++)
printf("%d",rev[i]);
printf("\nThe corrected message is: ");
rev[c]=!rev[c];
for(i=1;i<=7;i++)
printf("%d",rev[i]);
}
return 0;
}