#include"stdio.h"
#include"stdlib.h"
#include"math.h"
int hmatrix[3][7]={1,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,0,1};
int edata[7];
int syndrome[3];
int errdig;
int main()
{
int i,j;
system("clear");
printf("enter the encoded bits\n");
for(i=0;i<7;i++)
scanf("%d",&edata[i]);
for(i=0;i<3;i++)
for(j=0;j<7;j++)
syndrome[i]=syndrome[i]+edata[j]*hmatrix[i][j];
for(i=0;i<3;i++)
syndrome[i]=syndrome[i]%2;
errdig=4*syndrome[0]+2*syndrome[1]+1*syndrome[2];
if(0==errdig)
printf("error free data");
else
{
printf("error in bit number %d--%d\n",errdig,edata[errdig]);
errdig--;
if(1==edata[errdig])
edata[errdig]=0;
else
edata[errdig]=1;
}
for(i=3;i<7;i++)
printf("%d",edata[i]);
puts(" ");
}
This entry was posted
at 10:30 AM
and is filed under
Networks-programs
. You can follow any responses to this entry through the
comments feed
.