帮我解释一下下面的程序,谢谢! #include <cstdlib> #include <iostream> using namespace std;
int _tmain(int argc, _TCHAR* argv[]) { int H[3][7]= {{0,1,1,1,1,0,0}, {1,0,1,1,0,1,0}, {1,1,0,1,0,0,1}}; int X[7];
cout<<"press enter the Hamming code:"; cin>>X[0]>>X[1]>>X[2]>>X[3]>>X[4]>>X[5]>>X[6]; int y[3]; int Y[3]; int sum; int i,j;
int z[7]; int S[7]; for(i=0;i<3;++i) { sum=0; for(j=0;j<7;++j) { sum=sum + H[i][j]*X[j]; } y[i]=sum; } for(i=0;i<3;++i) Y[i]=y[i]&0x1;
sum=Y[0]+Y[1]+Y[2]; int Z[7]={0};
switch(sum) { case 0: break; case 1: if(Y[0]==1) Z[4]=1; if(Y[1]==1) Z[5]=1; if(Y[2]==1) Z[6]=1; break; case 2: if(Y[0]==0) Z[0]=1; if(Y[1]==0) Z[1]=1; if(Y[2]==0) Z[2]=1; break; case 3: Z[3]=1; break; } for(i=0;i<7;++i) { z[i]=X[i]+Z[i]; } for(i=0;i<7;++i) { S[i]=z[i]&0x1; } for(i=0;i<7;++i) cout<<S[i]; system("pause");
return 0; }