m序列c语言实现


演示,不是算法


void m4()
{
	int a[4]={1,0,0,1};
	int m[15];
	int temp;
	for(int i=0;i<15;i++){
		m[i] = a[0];
		printf("%d-%d-%d-%d\n",a[3],a[2],a[1],a[0]);
		//temp = (a[0]+a[3])%2;
		temp = (a[0]+a[1])%2;
		a[0] = a[1];
		a[1] = a[2];
		a[2] = a[3];
		a[3] = temp;
	}
	for(i=0;i<15;i++){
		printf("%d",m[i]);
	}
	printf("=m4\n");

}

void m5()
{
	int a[5]={1,0,0,0,0};
	int m[31];
	int temp;
	for(int i=0;i<31;i++){
		m[i] = a[0];
		printf("%d-%d-%d-%d-%d\n",a[4],a[3],a[2],a[1],a[0]);
		//temp = (a[0]+a[3])%2;
		temp = (a[0]+a[2])%2;
		a[0] = a[1];
		a[1] = a[2];
		a[2] = a[3];
		a[3] = a[4];
		a[4] = temp;
	}
	for(i=0;i<31;i++){
		printf("%d",m[i]);
	}
	printf("=m5\n");

}


void m8()
{
	int a[8]={1,0,0,0,0,0,0,0};
	int m[255];
	int temp;
	for(int i=0;i<255;i++){
		m[i] = a[0];
		printf("%d-%d-%d-%d-%d-%d-%d-%d\n",a[7],a[6],a[5],a[4],a[3],a[2],a[1],a[0]);
		//temp = (a[0]+a[3])%2;
		temp = (a[0]+a[2]+a[3]+a[4])%2;
		a[0] = a[1];
		a[1] = a[2];
		a[2] = a[3];
		a[3] = a[4];
		a[4] = a[5];
		a[5] = a[6];
		a[6] = a[7];
		a[7] = temp;
	}
	for(i=0;i<255;i++){
		printf("%d",m[i]);
	}
	printf("=m8\n");
	
}

void m18()
{
	//18阶反馈移位寄存器的初始值
	//(1000201)8=(1000000000010000001)2 c11=1  -> a[7]+a[0]
	int reg[18]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	int m[32],mi;
	int i,j,xor,temp;
	for(i=0;i<262144-1;i++){
		m[i%32]=reg[0];
		printf("%d ",reg[0]);
		temp = (reg[7]+reg[0])%2;
		
		for(j=0;j<18;j++){
			printf("%d",reg[j]);
			reg[j]=reg[j+1];
		}
		reg[17] = temp;
		//printf("%d",reg[17]);

		
		printf(" ");
		if((i+1)%32 == 0 && i!=0){
			mi = 0;
			for(j=0;j<32;j++){
				mi= (mi<<1) + (m[j] == 1 ? 1 : 0);
				printf("%d",m[j]);
			}
			printf("  mi=%u  ",mi);
		}
		if(i==262142){
			mi = 0;
			for(j=0;j<31;j++){
				mi= (mi<<1) + (m[j] == 1 ? 1 : 0);
				printf("%d",m[j]);
			}
			//最后用0补足
			mi= mi<<1;
			printf("%d",0);
			printf("  mi=%u  ",mi);
		}
		
		printf("   %d \n",i);
	}
	
	
}


posted on 2016-11-29 17:49  阮減显  阅读(1397)  评论(0编辑  收藏  举报

导航