unsigned long int ulPolynomial = 0x04c11db7; unsigned long int Reflect(unsigned long int ref, char ch) { unsigned long int value(0); // 交换bit0 和bit7,bit1 和bit6,类推 for(int i = 1; i < (ch + 1); i++) { if(ref & 1) value |= 1 << (ch - i); ref >>= 1; } return value; }
void BuildTable32(void) { unsigned long int crc,temp; // 256 个值 for(int i = 0; i <= 0xFF; i++) { temp=Reflect(i, 8); Table_CRC= temp<< 24; for (int j = 0; j < 8; j++) { unsigned long int t1,t2; unsigned long int flag=Table_CRC&0x80000000; t1=(Table_CRC << 1); if(flag==0) t2=0; else t2=ulPolynomial; Table_CRC =t1^t2 ; } crc=Table_CRC; Table_CRC = Reflect(Table_CRC, 32); } }