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

📄 encode.c

📁 通信类程序
💻 C
字号:
/*
**    FILE    : encode.c   
**    PURPOSE : The functions in this file enable encoding of a binary
**              data-file, given the generator polynomial of the code.
**    AUTHOR  : Bart De Canne, Belgium (bdc@barco.be)
**    COMPILER: BC++ 3.1 compiler
**    DEPENDENCIES:
**              Include-files: galois.h
**    DATE    : 01-09-1994
**    VERSION : 1.0
*/


#define _ENCODE
#include "galois.h"

static byte mask[] = {
   0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80
   };


/*
** Encodes raw data using current <pp_gen>.
** !! It is necessary to have a binary symbol field (0,1), so this function
**    only works for GF's which can be expressed as a power of 2 : GF(2^m).
**
** NOTE: Some structures in 'galois.h' could be declared more efficiently
** if calculations were done only in fields GF(2^m): e.g. the bit-represen-
** tation of a GF-element (<pe>) could be defined using one byte(for maximum
** symbol field of 256 elements) instead of an array of bytes for the
** general case.
** 
*/

static pPOLYNOM pp_data=NULL,
                pp_code=NULL;

void EncodeData(void) {

   long cnt=0;

   OpenInputStream(InFile);
   OpenOutputStream(OutFile);
   pp_data=AllocPolynom(pp_data,pp_gen->Base,K-1);
   pp_code=AllocPolynom(pp_code,pp_gen->Base,N-1);
   length /= (long)K*bps;
   START_PACIFIER;

   do{
      PACIFIER(100*cnt/length);
      READ_PP(pp_data)
      pp_code=MultPoly(pp_data,pp_gen,pp_code,po_s,COPY);
      WRITE_PP(pp_code);
      cnt++;
      }
   while(!EOFReached());
   PutBits(0,7);                                /* flush output buffer  */
   pp_data=FreePolynom(pp_data);
   pp_code=FreePolynom(pp_code);
   CloseInputStream();CloseOutputStream();
   STOP_PACIFIER;
   }


/*
** Searches for the index of the GF-element of which the right-aligned
** representation is given by <bit_repr>.
*/

int GetElementIndex(uint bit_repr) {

   int i,j;
   byte bit;

   BEGIN("GetElementIndex");
   for(i=0;i<pg_s->MaxNo;i++) {
      for(j=0;j<bps;j++) {
         bit = pg_s->pe[i].Alpha[j];
         if(bit_repr & mask[j]) {
            if(!bit) break;
            }
         else
            if(bit) break;
         }
      if(j==bps)
         return i;
      }
   ERROR;
   return 0;                                       /* avoid warning     */
   }


/*
** END OF ENCODE.C
*/

⌨️ 快捷键说明

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