home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_10
/
1010060a
< prev
next >
Wrap
Text File
|
1992-08-10
|
2KB
|
73 lines
/* FILE: mkcrc32.c
DATE: 910917:1632
LMOD: 910917:1706
FOR: generate tables for CCITT crc32
polynomial is
x**32+x**26+23+22+16+12+11+10+8+7+5+4+2+1+0
(x** left out after second step for short)
*/
#include <stdio.h>
long crc[256];
long magic=
(1L<<26)+(1L<<23)+(1L<<22)+(1L<<16)+(1L<<12)+
(1L<<11)+(1L<<10)+(1L<<8)+(1L<<7)+(1L<<5)+
(1L<<4)+4+2+1; /* the polynomial */
/* format string for output */
char ofmt[]="\t db\t0%02xh,0%02xh,0%02xh,0%02xh"
"\t; %02x-%02x\n";
long tblwd(long i) /* calculate table entry */
{
int c; long f;
for(i<<=24,c=0;c++<8;) {
f=i&0x80000000L; i<<=1;
if(f) i^=magic;
}
return(i);
}
main() /* output split CRC-32 tables in MASM form */
{
int i;
for(i=0;i<256;++i) crc[i]=tblwd(i);
printf(
"; crc tables: CCITT CRC-32, polynomial %lx\n",
magic);
printf("\ncrct0");
for(i=0;i<256;i+=4)
printf(ofmt,
(int)((crc[i]>>24)&0xff),
(int)((crc[i+1]>>24)&0xff),
(int)((crc[i+2]>>24)&0xff),
(int)((crc[i+3]>>24)&0xff),
i,i+3);
printf("\ncrct1");
for(i=0;i<256;i+=4)
printf(ofmt,
(int)((crc[i]>>16)&0xff),
(int)((crc[i+1]>>16)&0xff),
(int)((crc[i+2]>>16)&0xff),
(int)((crc[i+3]>>16)&0xff),
i,i+3);
printf("\ncrct2");
for(i=0;i<256;i+=4)
printf(ofmt,
(int)((crc[i]>>8)&0xff),
(int)((crc[i+1]>>8)&0xff),
(int)((crc[i+2]>>8)&0xff),
(int)((crc[i+3]>>8)&0xff),
i,i+3);
printf("\ncrct3");
for(i=0;i<256;i+=4)
printf(ofmt,
(int)(crc[i]&0xff),
(int)(crc[i+1]&0xff),
(int)(crc[i+2]&0xff),
(int)(crc[i+3]&0xff),
i,i+3);
printf("\n");
exit(0);
}