home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume28
/
crc16
/
part01
/
make_crc_tab.c
< prev
Wrap
C/C++ Source or Header
|
1992-03-15
|
809b
|
38 lines
/* The CRC polynomial is represented in binary; each bit is the
coefficient of a term. The low-order bit corresponds to the
highest-order coefficient (yes, this does seem backwards).
The bit sequences for some common CRC polynomials:
CRC-16: 16 15 2
x + x + x + 1 0x14003
CCITT: 16 12 5
x + x + x + 1 0x10811
The CCITT polynomial is used for Kermit.
*/
#define CCITT 0x10811
#define CRC_16 0x14003
void make_16_bit_crc_tab(poly) unsigned int poly;
{unsigned int i,j, M;
printf("unsigned short crc_table[256] = {\n");
for (i=0; i<256; i++){
M = i;
for (j=8;j>0;j--){
if (M & 1){M ^= poly;}
M >>= 1;}
#ifdef AMIGA
printf("0x%x,\n", M);
#else
printf("%#x,\n", M);
#endif
}
printf("};\n");
}
void main(){make_16_bit_crc_tab(CCITT);}