⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hanresult.txt

📁 Hamming码是一类非常重要的线性分组码,它能纠正全部一位错误上传的是Hamming码的编码和译码的Java程序以及编写程序时所写的文档
💻 TXT
字号:

// ó?êy×éêμ??±à??

import java.awt.*; 
import java.io.*;
import java.lang.*;


public class Array50{
	public static void main(String args[]){

		int Sbefore[][][][]=new int[30][3][1][7];
		int S[][][]   =new int[30][3][1];		
		int ST[][][]  =new int[30][1][3];				
		int HT[][][]  =new int[ 7][1][3];
		int nC[]      =new int[30];	
		int counter,check,sign=0,finish;
		int i,j,k,r;

		int H[][][]={{{0,1,1,1,1,0,0}},
		             {{1,0,1,1,0,1,0}},
		             {{1,1,0,1,0,0,1}}};		

		int C[][][]={{{0,0,0,1,1,1,1}},{{1,0,0,1,1,1,1}},{{1,1,0,1,0,1,1}},
		             {{1,1,0,1,1,1,0}},{{1,0,0,0,1,0,0}},{{1,1,0,1,0,0,1}},
		             {{1,0,0,0,1,0,1}},{{1,0,0,1,1,1,1}},{{1,1,0,1,0,1,0}}};	
		             		
		int z[][]  ={{1,3,5}};		
        int	nColumn=999;			

        System.out.println("打印输入二进制代码矩阵H");
        
        for(r=0;r<C.length;r++){
        	System.out.print("     C["+r+"]=");
        	for(j=0;j<H[0].length;j++){
        		for(k=0;k<H[0][0].length;k++){
        			System.out.print(""+C[r][j][k]);        			
        		}
        	}
        	System.out.println();
        }

        for(i=0;i<H.length;i++){
        	counter=0;
        	for(j=0;j<H[0].length;j++){
        		for(k=0;k<H[0][0].length;k++){
         			HT[k][j][i]=H[i][j][k];
        			counter++;
//        			if(counter%3==0) System.out.print("  ");
        		}
        	}
//  			System.out.println("");
        }
        
        System.out.println();
        


        System.out.println("打印校验矩阵H");
        for(i=0;i<HT.length;i++){
        	counter=0;
        	System.out.print("H["+i+"]=");
        	for(j=0;j<HT[0].length;j++){
        		for(k=0;k<HT[0][0].length;k++){
         			HT[i][j][k]=H[k][j][i];
        			System.out.print(""+HT[i][j][k]);        			
        			counter++;
        			if(counter%3==0) System.out.print("  ");
        		}
        	}
  			System.out.println("");
        }
         
                
 

 
        
        for(r=0;r<C.length;r++){
        for(i=0;i<H.length;i++){
        	counter=0;
//        	System.out.print("Sbefore["+r+"]["+i+"]=");
        	for(j=0;j<H[0].length;j++){
        		for(k=0;k<H[0][0].length;k++){
         			Sbefore[r][i][j][k]=H[i][j][k]&C[r][j][k];
//        			System.out.print(""+Sbefore[r][i][j][k]);        			
        			counter++;
//        			if(counter%7==0) System.out.print("  ");
        		}
        	}
//  			System.out.println("");
        }
        }


        for(r=0;r<C.length;r++){
        for(i=0;i<Sbefore[0].length;i++){
        	counter=check=0;
        	for(j=0;j<Sbefore[0][0].length;j++){
        		for(k=0;k<H[0][0].length;k++){
         			if(Sbefore[r][i][j][k]==1) check^=1;
        		}
        		S[r][i][j]=check;
        	}
        }
        }
        
        System.out.println();

        System.out.println("打印伴随式H");

        for(i=0;i<C.length;i++){
        	counter=0;
        	System.out.print("S["+i+"]=");
        	for(j=0;j<ST[0].length;j++){
        		for(k=0;k<ST[0][0].length;k++){
         			ST[i][j][k]=S[i][k][j];
        			System.out.print(""+ST[i][j][k]);        			
        			counter++;
        			if(counter%3==0) System.out.print("  ");
        		}
        	}
  			System.out.println("");
        }
 

        for(r=0;r<C.length;r++){
//        	System.out.print("     S["+r+"]=");
        for(i=0;i<S[0].length;i++){
        	counter=0;
        	for(j=0;j<S[0][0].length;j++){
//     			    System.out.print(" S["+r+"]["+i+"]["+j+"]="+S[r][i][j]);        			
//       			    System.out.print(""+S[r][i][j]);        			
        			counter++;
//        			if(counter%3==0) System.out.println();
        	}
        } 
        System.out.println();
        }

     	try{
	    	System.in.read();
	    }
	    catch(Exception e){	}
	    
   
     for(r=0;r<C.length;r++){
        finish=0;
        for(k=0;k<H[0][0].length;k++){
        	sign=0; //
        	for(i=0;i<H.length;i++){
        		for(j=0;j<H[0].length;j++){
//        			System.out.println(" S["+r+"]["+i+"]["+j+"]="+S[r][i][j]);
                }
            }    
        }
     }

 
 	    
     	try{
	    	System.in.read();
	    }
	    catch(Exception e){	}


     System.out.println("begin");
     for(r=0;r<C.length;r++){
        finish=0;
        nColumn=999;
        for(i=0;i<HT.length;i++){
//        	sign=0; //
        	for(j=0;j<HT[0].length;j++){
        		for(k=0;k<HT[0][0].length;k++){
        			System.out.println(" HT["+r+"]["+i+"]["+j+"]["+k+"]="+ST[i][j][k]);
        			if(HT[i][j][k]!=ST[r][j][k]){
        				sign=1;
        				break;
        			}
        			else sign=0;
        		}
        		if(sign==1){
        			finish=0;
        			break;
        		}
        		else finish=1;
        	}
        	if((finish==1)&&(i<HT.length)){
        		nColumn=i;
        		break;
        	}
        }

       	    if(nColumn>HT.length)
       	    	System.out.println(" No error receive=input");
       	    else{
       	    	System.out.println("1 erroer occured in the position "+nColumn);
       	    	System.out.println("system has change it");
       	        C[r][0][nColumn]^=1;
       	    }
        
     }

     	try{
	    	System.in.read();
	    }
	    catch(Exception e){	}

	}		
}	




输入二进制代码矩阵
     C[0]=0001111  
     C[1]=1001111
     C[2]=1101011
     C[3]=1101110
     C[4]=1000100
     C[5]=1101001
     C[6]=1000101
     C[7]=1001111
     C[8]=1101010

对应伴随式S

S[0]=000
S[1]=011
S[2]=010
S[3]=111
S[4]=111
S[5]=000
S[6]=110
S[7]=011
S[8]=011

出错位置
     C[0]=0001111  No error receive=input  
     C[1]=1001111  1 erroer occured in the position 0  system has change it
     C[2]=1101011  1 erroer occured in the position 5  system has change it
     C[3]=1101110  1 erroer occured in the position 3  system has change it
     C[4]=1000100  1 erroer occured in the position 3  system has change it
     C[5]=1101001  No error receive=input
     C[6]=1000101  1 erroer occured in the position 2  system has change it
     C[7]=1001111  1 erroer occured in the position 0  system has change it
     C[8]=1101010  1 erroer occured in the position 0  system has change it

经过纠错后输出代码

     C[0]=0001111
     C[1]=0001111
     C[2]=1101001
     C[3]=1100110
     C[4]=1001100
     C[5]=1101001
     C[6]=1010101
     C[7]=0001111
     C[8]=0101010


??????H
H[0]=011
H[1]=101
H[2]=110
H[3]=111
H[4]=100
H[5]=010
H[6]=001

?????H
S[0]=000
S[1]=011
S[2]=010
S[3]=111
S[4]=111
S[5]=000
S[6]=110
S[7]=011
S[8]=011










begin
 HT[0][0][0][0]=0
 HT[0][0][0][1]=0
 HT[0][1][0][0]=0
 HT[0][2][0][0]=0
 HT[0][3][0][0]=1
 HT[0][4][0][0]=1
 HT[0][5][0][0]=0
 HT[0][5][0][1]=0
 HT[0][6][0][0]=1
 HT[0][6][0][1]=1
 HT[0][6][0][2]=0
 No error receive=input
 HT[1][0][0][0]=0
 HT[1][0][0][1]=0
 HT[1][0][0][2]=0
1 erroer occured in the position 0
system has change it
 HT[2][0][0][0]=0
 HT[2][0][0][1]=0
 HT[2][0][0][2]=0
 HT[2][1][0][0]=0
 HT[2][2][0][0]=0
 HT[2][3][0][0]=1
 HT[2][4][0][0]=1
 HT[2][5][0][0]=0
 HT[2][5][0][1]=0
 HT[2][5][0][2]=0
1 erroer occured in the position 5
system has change it
 HT[3][0][0][0]=0
 HT[3][1][0][0]=0
 HT[3][1][0][1]=1
 HT[3][2][0][0]=0
 HT[3][2][0][1]=1
 HT[3][2][0][2]=0
 HT[3][3][0][0]=1
 HT[3][3][0][1]=1
 HT[3][3][0][2]=1
1 erroer occured in the position 3
system has change it
 HT[4][0][0][0]=0
 HT[4][1][0][0]=0
 HT[4][1][0][1]=1
 HT[4][2][0][0]=0
 HT[4][2][0][1]=1
 HT[4][2][0][2]=0
 HT[4][3][0][0]=1
 HT[4][3][0][1]=1
 HT[4][3][0][2]=1
1 erroer occured in the position 3
system has change it
 HT[5][0][0][0]=0
 HT[5][0][0][1]=0
 HT[5][1][0][0]=0
 HT[5][2][0][0]=0
 HT[5][3][0][0]=1
 HT[5][4][0][0]=1
 HT[5][5][0][0]=0
 HT[5][5][0][1]=0
 HT[5][6][0][0]=1
 HT[5][6][0][1]=1
 HT[5][6][0][2]=0
 No error receive=input
 HT[6][0][0][0]=0
 HT[6][1][0][0]=0
 HT[6][1][0][1]=1
 HT[6][2][0][0]=0
 HT[6][2][0][1]=1
 HT[6][2][0][2]=0
1 erroer occured in the position 2
system has change it
 HT[7][0][0][0]=0
 HT[7][0][0][1]=0
 HT[7][0][0][2]=0
1 erroer occured in the position 0
system has change it
 HT[8][0][0][0]=0
 HT[8][0][0][1]=0
 HT[8][0][0][2]=0
1 erroer occured in the position 0
system has change it
 ???????????H
     C[0]=0001111
     C[1]=0001111
     C[2]=1101001
     C[3]=1100110
     C[4]=1001100
     C[5]=1101001
     C[6]=1010101
     C[7]=0001111
     C[8]=0101010

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -