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

📄 循环码.txt

📁 (7
💻 TXT
字号:
/*
 *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++)                               /*进行除法操作*/
        {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];            /*进行编码操作*/
     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]);                          /*输出编码结果*/
     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++)                                         /*进入除法电路*/
  {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");           /*输入错误位数大于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++)                                         /*纠正一位错误*/
   {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位译码结果*/
   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();}       /*输入错误提示*/

    }
/*
 * 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()                                  /*选择继续编码或是退出*/
       {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()                                     /*选择继续译码或是退*/
   { 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()                             /*进入界面*/
{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("    **               SHMUniversity                       **\n");
printf("    **               Days  : 2008.11                         **\n");
printf("****************************************************************\n");
}






⌨️ 快捷键说明

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