?? 循環(huán)碼.txt
字號(hào):
/*
*File. Cyclic code translation .c
*---------------------------------------------------
*This Program is used to carry on the code and he
*decoding to (7,3)cyclic code.
*/
#include<stdio.h>
#include<math.h>
/*Function prototypes*/
void GiveInstruction();
void Begain();
void Newinput1();
void Newinput2();
void Newinput3();
void Code();
void Decoding();
/*Main progam*/
main()
{
GiveInstruction();
Begain();
}
/*
* Funtion:Code
* Usage :Code();
* ------------------------
* This funtion reads in array infomation code of 3bit
* from the user and output that code result.
*/
void Code()
{
int Input[3];
int Output[7];
int reg[4]={0,0,0,0};
int temp,i,j;
printf("Please input the information code :\n");
for(i=0;i<3;i++)
scanf("%d",&Input[i]); /*輸入信息碼*/
for(i=0;i<3;i++) /*進(jìn)行除法操作*/
{temp=reg[3]+Input[i];
if(temp==2) temp=0;
reg[3]=reg[2]+temp;
if(reg[3]==2)reg[3]=0;
reg[2]=reg[1]+temp;
if(reg[2]==2)reg[2]=0;
reg[1]=reg[0];
reg[0]=temp;
}
for(i=0;i<3;i++) Output[i]=Input[i]; /*進(jìn)行編碼操作*/
for(i=3;i<7;i++)
{
temp=reg[3];
for(j=3;j>0;j--)
reg[j]=reg[j-1];
reg[0]=0;
Output[i]=temp;
}
printf("________________________________________");
printf("\n");
printf(" The information code output is: \n");
for(i=0;i<7;i++)
printf( " %d ",Output[i]); /*輸出編碼結(jié)果*/
printf("\n");
printf("________________________________________");
printf("\n");
Newinput1();
}
/*
* Funtion:Decoding
* Usage :Decoding();
* ------------------------
* This funtion reads in array infomation code of 7bit
* from the user and output that decoding result.
*/
void Decoding()
{ int Input[7],Output[7];
int reg[4]={0,0,0,0,};
int temp,i,d,x,p;
printf("Please input the information code of bit7:\n");
for(i=0;i<7;i++)
scanf(" %d",&Input[i]); /*輸入接受碼組*/
for(i=0;i<7;i++) /*進(jìn)入除法電路*/
{temp=reg[3];
reg[3]=reg[2]+temp;
if(reg[3]==2)reg[3]=0;
reg[2]=reg[1]+temp;
if(reg[2]==2)reg[2]=0;
reg[1]=reg[0];
reg[0]=temp+Input[i];
if(reg[0]==2)reg[0]=0;
}
p=reg[3]+2*reg[2]+4*reg[1]+8*reg[0];
if(p!=1&&p!=2&&p!=3&&p!=7&&p!=8&&p!=13&&p!=14&&p!=0)
{printf("*************************\n"); /*輸入錯(cuò)誤位數(shù)大于2位*/
printf("** \"The error >=2\" **\n");
printf("*************************\n");
Newinput3();
getchar();
}
printf("___________________________________________\n");
printf("s(x)=");
for(i=3;i>=0;i--)
printf(" %d",reg[i]);
printf("\n");
for(i=0;i<7;i++) /*糾正一位錯(cuò)誤*/
{d=reg[3]*reg[2]*reg[1]*(!reg[0]);
Output[i]=d+Input[i];
if(Output[i]==2) Output[i]=0;
temp=reg[3];
x=0;
reg[3]=temp+reg[2];
if(reg[3]==2)reg[3]=0;
reg[2]=reg[1]+temp;
if(reg[2]==2)reg[2]=0;
reg[1]=reg[0];
reg[0]=temp+x;
} /*輸出3位信息源*/
printf("The decoding bit3 is:");
for(i=0;i<3;i++)
printf(" %d ",Output[i]);
printf("\n");
printf("The Decoding bit7 is:"); /*輸出7位譯碼結(jié)果*/
for(i=0;i<7;i++)
printf(" %d ",Output[i]);
printf("\n");
printf("___________________________________________\n");
Newinput2();
}
/*
* Funtion:Begain
* Usage :Begain();
* ---------------------------
* This procdure prints out instruction to the user.
* The user chooses the operation according to the explanation
*which oneself needs.
*/
void Begain()
{ /*選擇操作*/
char ch;
printf(" -----------------------------------------------------------------");
printf("\n");
printf( " -- If must carry on the code please to input 'c' --");
printf("\n");
printf(" -- If must carry on the decoding code please to input 'd' --");
printf("\n");
printf(" -----------------------------------------------------------------");
printf("\n\n\n");
ch=getchar();
if(ch=='c') Code();
else if(ch=='d') Decoding();
else if(ch=='\n') Begain();
else {printf("\"Input error!please input again!\"\n");Begain();} /*輸入錯(cuò)誤提示*/
}
/*
* Funtion:Newinput1
* Usage :Newinput1();
* ---------------------------
* This procdure prints out instruction to the user.
* The user continues this code operation perhaps the
*withdrawal according to the explanation *choice.
*/
void Newinput1() /*選擇繼續(xù)編碼或是退出*/
{int t;
printf("------------------------\n");
printf("-- continue-----1 --\n");
printf("-- exit---------0 --\n");
printf("------------------------\n");
scanf("%d",&t);
if(t==1) Code();
else if(t==0)
printf("\n");
}
/*
* Funtion:Newinput2
* Usage :Newinput2();
* ---------------------------
* This procdure prints out instruction to the user.
* The user continues this decoded operation perhaps
* the withdrawal according to the prompt * * choice.
*/
void Newinput2() /*選擇繼續(xù)譯碼或是退*/
{ int t;
printf("------------------------\n");
printf("-- continue-----1 --\n");
printf("-- exit---------0 --\n");
printf("------------------------\n");
scanf("%d",&t);
if(t==1) Decoding();
else if(t==0) Begain();
}
/*
* Funtion:Newinput3
* Usage :Newinput3();
* ---------------------------
* This procdure prints out instruction to the user.
* Then Continues to carry on this operation.
*/
void Newinput3()
{printf("Please input the information code 7bit again:\n");
Decoding();}
/*
* Funtion:GiveInstruction
* Usage :GiveInstruction();
* ---------------------------
* This procdure prints out instruction to the user.
*/
void GiveInstruction() /*進(jìn)入界面*/
{printf("*****************************************************************\n");
printf("** WELCOME TO USE THIS PROGRAM **\n");
printf("** **\n");
printf("** **\n");
printf("** **\n");
printf(" **This software main function is carries on the code and **\n");
printf("** the decoding to (7,3) cyclic code. **\n");
printf("** **\n");
printf(" ** ShangHai Maritime University **\n");
printf(" ** Days : 2008.11 **\n");
printf("****************************************************************\n");
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -