HDB3编码-C语言程序班级:姓名:学号:第1页共5页#includestdio.h#defineM100intorigin[M],AMIcode[M];voidAMI(intn);voidHDB3(intn);voidmain(){inti,n;printf(输入原码位数:);scanf(%d,&n);printf(输入原码:);for(i=0;in;i++)scanf(%d,&origin[i]);AMI(n);printf(AMI:);for(i=0;in;i++)printf(%5d,AMIcode[i]);printf(\n);HDB3(n);printf(HDB3:);for(i=0;in;i++)printf(%5d,AMIcode[i]);printf(\n);}voidAMI(intn){inti,k=1;for(i=0;in;i++){if(origin[i]==0)AMIcode[i]=0;elseif(origin[i]==1){AMIcode[i]=k;k=-k;}else;}}voidHDB3(intn){inti=0,m,j=0,v,w,x=0;while(in){m=0;while(AMIcode[i]==0&&m4&&in){m++;i++;}if(m==4)j++;第2页共5页if(j==1&&m==4){AMIcode[i-1]=AMIcode[i-5];v=AMIcode[i-1];}if(j1&&m==4){AMIcode[i-1]=-v;if(AMIcode[i-1]!=AMIcode[i-5]){AMIcode[i-4]=-AMIcode[i-5];AMIcode[i-1]=AMIcode[i-4];w=AMIcode[i-1];while(x3&&in){if((AMIcode[i])==1){AMIcode[i]=-w;w=AMIcode[i];}if(AMIcode[i]==0&&AMIcode[i+1]==0)x++;if(AMIcode[i]==0&&AMIcode[i+1]==0)x++;i++;}}else;v=AMIcode[i-1];}if(m==0)i++;else;}}第3页共5页原码:11000011100011第4页共5页原码:101100001001第5页共5页原码:111000000110第6页共1页