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

📄 bchenco192.cpp

📁 BCH编解码的源代码
💻 CPP
字号:
/******************************************
        BCH(192,116,21) ENCODER
      由本原BCH(255,179,21)截取
*******************************************/

#include <stdio.h>
#define N 192      
#define K 116
#define R 76

void main()
{
	static int cx[N];
	static int mx[K];
	static int gx[R+1]={1,0,1,
		1,0,1, 0,0,1, 0,0,0, 0,0,0, 1,1,0,
	    0,1,1, 1,0,0, 0,0,1, 0,1,0, 1,1,0,
	    0,0,1, 0,0,0, 0,0,1, 1,1,0, 1,1,1,
	    1,0,0, 1,1,1, 0,0,0, 1,0,0, 1,1,1,
	    0,0,1, 0,1,0, 0,1,1, 0,1,0, 0,1};    /*生成多项式*/

	static int rx[R];   /*校验元*/
	int i,j,temp;
	FILE *fp1,*fp2;

	fp1=fopen("e:\\radiowork\\bch\\test192\\msg5.txt","r");
	fp2=fopen("e:\\radiowork\\bch\\test192\\code5.txt","w");
	rewind(fp1);
	rewind(fp2);

	for(i=0;i<K;i++)
		fscanf(fp1,"%d",&mx[i]);
	
	/****求余式 rx******/
	for(j=K-1;j>=0;j--)
	{
		temp=rx[R-1];
		for(i=R-1;i>0;i--)
			if(gx[i]==0)
				rx[i]=rx[i-1];
			else if(gx[i]==1)
				rx[i]=(mx[j]^temp)^rx[i-1];
		rx[0]=mx[j]^temp;
	}
	
	for(i=N-1;i>=N-K;i--)
		cx[i]=mx[i-(N-K)];    /*the mx's MSB vs. cx's MSB*/
	for(i=N-K-1;i>=0;i--)
		cx[i]=rx[i];
	
	/*cx[0]~cx[N-1]输出*/
	printf("\noutput the BCH(192,116) code cx(cx[0]~cx[N-1]):\n");
	for(i=0;i<N;i++)
	{
		fprintf(fp2,"%d ",cx[i]);
		printf("%d ",cx[i]);
		
	}
	printf("\n");
	
	fclose(fp1);
	fclose(fp2);

}

⌨️ 快捷键说明

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