Friday, April 15, 2016

W.A.P to implement Hamming Code Distance method.



#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int info[7],rec[7],i,c1,c2,c3,c;
clrscr();
printf("\n Successful For Message Of 4 Bits of Size \nEnter Message Bit One By One: ");

scanf("%d%d%d%d",&info[0],&info[1],&info[2],&info[4]);
info[6]=info[0]^info[2]^info[4];
info[5]=info[0]^info[1]^info[4];
info[3]=info[0]^info[1]^info[2];
printf("\n The Encoded Bits are given below : \n");

for(i=0;i<7;i++)
{
printf("%d",info[i]);
}
printf("\n Enter The Received info Bit One By One : ");
for(i=0;i<7;i++)
{
scanf("%d",&rec[i]);
}

c1=rec[6]^rec[4]^rec[2]^rec[0];
c2=rec[5]^rec[4]^rec[1]^rec[0];
c3=rec[3]^rec[2]^rec[1]^rec[0];
c=c3*4+c2*2+c1;

if(c==0)
{
printf("\n Non-Inturrupted ");
}
else
{
printf("\n Error On The Position : %d \nThe Correct Message Is \n ",c);

if(rec[7-c]==0)
rec[7-c]=1;
else
rec[7-c]=0;
for(i=0;i<7;i++)
{
printf("%d",rec[i]);
}
}
getch();
}

No comments:

Post a Comment