HAMMING CODE
-------------------------------------------
#include<iostream.h>
using namespace std;
int main()
{
int d[5],p[4];
int c[8],r[8];
int flag;
int count=0;
cout<<"Enter the data bits(4 bit):";
for(int i=1;i<5;i++)
{
cin>>d[i];
}
c[7]=d[1];
c[6]=d[2];
c[5]=d[3];
c[3]=d[4];
c[1]=c[3]^c[5]^c[7];
c[2]=c[3]^c[6]^c[7];
c[4]=c[5]^c[6]^c[7];
cout<<"\nThe send data :";
for(int j=7;j>=1;j--)
{
cout<<c[j];
}
cout<<"\nEnter codeword received (7 digit):";
for(int k=7;k>=1;k--)
cin>>rd[k];
for(int l=7;l>=1;l--)
{
if(c[l]!=rd[l])
{ count++; }
}
if(count>1)
{ cout<<endl<<"More than 1 error:";}
else
{
p[1]=r[1]^r[3]^r[5]^r[7];
p[2]=r[2]^r[3]^r[6]^r[7];
p[3]=r[4]^r[5]^r[6]^r[7];
flag=p[1]*1+p[2]*2+p[3]*4;
if(flag==0)
cout<<"No Error";
else
cout<<"Error at bit position:"<<flag;
return 0;
}
}
No comments:
Post a Comment