24 #define WIDTH (8 * sizeof(crc))
25 #define TOPBIT (1 << (WIDTH - 1))
27 #if (REFLECT_DATA == CRC_TRUE)
29 #define REFLECT_DATA(X) ((unsigned char) reflect((X), 8))
32 #define REFLECT_DATA(X) (X)
35 #if (REFLECT_REMAINDER == CRC_TRUE)
36 #undef REFLECT_REMAINDER
37 #define REFLECT_REMAINDER(X) ((crc) reflect((X), WIDTH))
39 #undef REFLECT_REMAINDER
40 #define REFLECT_REMAINDER(X) (X)
57 reflect(
unsigned long data,
unsigned char nBits)
59 unsigned long reflection = 0x00000000;
65 for (bit = 0; bit < nBits; ++bit)
72 reflection |= (1 << ((nBits - 1) - bit));
109 for (dividend = 0; dividend < 256; ++dividend)
114 remainder = dividend << (
WIDTH - 8);
119 for (bit = 8; bit > 0; --bit)
130 remainder = (remainder << 1);