const int order = 16; const unsigned long polynom = 0x1021; const int direct = 1; const unsigned long crcinit = 0xffff; const unsigned long crcxor = 0xffff; const int refin = 1; const int refout = 1; unsigned long crcmask; unsigned long crchighbit; unsigned long crcinit_direct; unsigned long crcinit_nondirect; unsigned char string[] = {0xFF,0x01,0x15,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00}; unsigned long reflect (unsigned long crc, int bitnum) { // reflects the lower 'bitnum' bits of 'crc' unsigned long i, j=1, crcout=0; for (i=(unsigned long)1<<(bitnum-1); i; i>>=1) { if (crc & i) crcout|=j; j<<= 1; } return (crcout); } unsigned long crcbitbybit(unsigned char* p, unsigned long len) { unsigned long i, j, c, bit; unsigned long crc = crcinit_nondirect; for (i=0; i>=1) { bit = crc & crchighbit; crc<<= 1; if (c & j) crc|= 1; if (bit) crc^= polynom; } } for (i=0; i>= 1; if (bit) crc|= crchighbit; } crcinit_nondirect = crc; } crc_wert = crcbitbybit((unsigned char *)string, strlen(string)); printf("\n\ncrc_wert:0x%x",crc_wert); }