#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<String.h>
void main()
{
int k[4][7];
int p=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<7;j++)
{
krs: cout<<"Enter the value of matrix cell["<<i<<"]["<<j<<"]";
cin>>p;
if(p==0||p==1)
{
k[i][j]=p;
}
else
{
cout<<"Please Enter the right value";
goto krs;
}
}
}
clrscr();
char u[4];
pqrs:cout<<"Enter the String";
cin>>u;
int error=0;
for(i=0;i<4;i++)
{
if(!(u[i]=='0'||u[i]=='1'))
{
error=1;
}
}
if(error==1)
{
cout<<"Please Enter String containg 1 or 0";
goto pqrs;
}
int uc[4][1];
for(i=0;i<4;i++)
{
if(u[i]=='1')
{
uc[i][0]=1;
}
else
{
uc[i][0]=0;
}
}
int hamm[1][7];
for(i=0;i<1;i++)
{
for(int j=0;j<7;j++)
{
int gs=0;
for(int l=0;l<4;l++)
{
int pp=uc[i][l]*k[l][j];
gs=gs+pp;
gs=gs%2;
}
hamm[i][j]=gs;
}
}
int hamming[7][1];
for(i=0;i<1;i++)
{
for(int j=0;j<7;j++)
{
hamming[j][i]=hamm[i][j];
cout<<hamm[i][j]<<"\n";
}
}
getch();
clrscr();
char w[7];
pqr:cout<<"Enter the retrieved String";
cin>>w;
error=0;
for(i=0;i<7;i++)
{
if(!(w[i]=='0'||w[i]=='1'))
{
error=1;
}
}
if(error==1)
{
cout<<"Please Enter String containg 1 or 0";
goto pqr;
}
clrscr();
for(i=0;i<7;i++)
{
if(w[i]=='1')
hamming[i][0]=1;
else
hamming[i][0]=0;
}
int hamms[3][7];
cout<<"Enter the H matric";
for(i=0;i<3;i++)
{
for(int j=0;j<7;j++)
{
krss: cout<<"Enter the value of matrix cell["<<i<<"]["<<j<<"]";
cin>>p;
if(p==0||p==1)
{
hamms[i][j]=p;
}
else
{
cout<<"Please Enter the right value";
goto krss;
}
}
}
int err[3][1];
for(i=0;i<3;i++)
{
for(int j=0;j<1;j++)
{
int gs=0;
for(int l=0;l<7;l++)
{
int pp=hamms[i][l]*hamming[l][j];
gs=gs+pp;
gs=gs%2;
}
err[i][j]=gs;
}
}
int a=err[0][0]*1+err[1][0]*2+err[1][1]*4;
if(a>0)
{
cout<<"\nincorrected Hamming Code\n";
for(i=0;i<7;i++)
cout<<hamming[i][0];
for(int i=0;i<7;i++)
{
if(hamming[a-1][0]==1)
hamming[a-1][0]=0;
else
hamming[a-1][0]=1;
}
cout<<"\ncorrected Hamming Code\n";
for(i=0;i<7;i++)
cout<<hamming[i][0];
}
else{
cout<<"correct hamming code";}
}
For more codes please goto http://codesofprogramming.blogspot.in/
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<String.h>
void main()
{
int k[4][7];
int p=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<7;j++)
{
krs: cout<<"Enter the value of matrix cell["<<i<<"]["<<j<<"]";
cin>>p;
if(p==0||p==1)
{
k[i][j]=p;
}
else
{
cout<<"Please Enter the right value";
goto krs;
}
}
}
clrscr();
char u[4];
pqrs:cout<<"Enter the String";
cin>>u;
int error=0;
for(i=0;i<4;i++)
{
if(!(u[i]=='0'||u[i]=='1'))
{
error=1;
}
}
if(error==1)
{
cout<<"Please Enter String containg 1 or 0";
goto pqrs;
}
int uc[4][1];
for(i=0;i<4;i++)
{
if(u[i]=='1')
{
uc[i][0]=1;
}
else
{
uc[i][0]=0;
}
}
int hamm[1][7];
for(i=0;i<1;i++)
{
for(int j=0;j<7;j++)
{
int gs=0;
for(int l=0;l<4;l++)
{
int pp=uc[i][l]*k[l][j];
gs=gs+pp;
gs=gs%2;
}
hamm[i][j]=gs;
}
}
int hamming[7][1];
for(i=0;i<1;i++)
{
for(int j=0;j<7;j++)
{
hamming[j][i]=hamm[i][j];
cout<<hamm[i][j]<<"\n";
}
}
getch();
clrscr();
char w[7];
pqr:cout<<"Enter the retrieved String";
cin>>w;
error=0;
for(i=0;i<7;i++)
{
if(!(w[i]=='0'||w[i]=='1'))
{
error=1;
}
}
if(error==1)
{
cout<<"Please Enter String containg 1 or 0";
goto pqr;
}
clrscr();
for(i=0;i<7;i++)
{
if(w[i]=='1')
hamming[i][0]=1;
else
hamming[i][0]=0;
}
int hamms[3][7];
cout<<"Enter the H matric";
for(i=0;i<3;i++)
{
for(int j=0;j<7;j++)
{
krss: cout<<"Enter the value of matrix cell["<<i<<"]["<<j<<"]";
cin>>p;
if(p==0||p==1)
{
hamms[i][j]=p;
}
else
{
cout<<"Please Enter the right value";
goto krss;
}
}
}
int err[3][1];
for(i=0;i<3;i++)
{
for(int j=0;j<1;j++)
{
int gs=0;
for(int l=0;l<7;l++)
{
int pp=hamms[i][l]*hamming[l][j];
gs=gs+pp;
gs=gs%2;
}
err[i][j]=gs;
}
}
int a=err[0][0]*1+err[1][0]*2+err[1][1]*4;
if(a>0)
{
cout<<"\nincorrected Hamming Code\n";
for(i=0;i<7;i++)
cout<<hamming[i][0];
for(int i=0;i<7;i++)
{
if(hamming[a-1][0]==1)
hamming[a-1][0]=0;
else
hamming[a-1][0]=1;
}
cout<<"\ncorrected Hamming Code\n";
for(i=0;i<7;i++)
cout<<hamming[i][0];
}
else{
cout<<"correct hamming code";}
}
For more codes please goto http://codesofprogramming.blogspot.in/
No comments:
Post a Comment