home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume28 / crc16 / part01 / make_crc_tab.c < prev   
C/C++ Source or Header  |  1992-03-15  |  809b  |  38 lines

  1. /* The CRC polynomial is represented in binary; each bit is the
  2. coefficient of a term. The low-order bit corresponds to the
  3. highest-order coefficient (yes, this does seem backwards).
  4.  
  5. The bit sequences for some common CRC polynomials:
  6.  
  7. CRC-16:     16    15    2
  8.     x   + x   + x  + 1    0x14003
  9.  
  10. CCITT:     16    12    5
  11.     x   + x   + x  + 1    0x10811
  12.  
  13. The CCITT polynomial is used for Kermit.
  14.  
  15. */
  16.  
  17. #define CCITT 0x10811
  18. #define CRC_16 0x14003
  19.  
  20. void make_16_bit_crc_tab(poly) unsigned int poly;
  21.   {unsigned int i,j, M;
  22.   printf("unsigned short crc_table[256] = {\n");
  23.   for (i=0; i<256; i++){
  24.     M = i;
  25.     for (j=8;j>0;j--){
  26.       if (M & 1){M ^= poly;}
  27.       M >>= 1;}
  28. #ifdef AMIGA
  29.     printf("0x%x,\n", M);
  30. #else
  31.     printf("%#x,\n", M);
  32. #endif
  33.     }
  34.   printf("};\n");
  35. }
  36.  
  37. void main(){make_16_bit_crc_tab(CCITT);}
  38.