// CRC.cpp : Defines the entry point for the console application. // #include "math.h" unsigned char mess[8], reply[8]; void main() { unsigned char highbyte,lowbyte; unsigned short crc,thisbyte,i,shift,lastbit; mess[0]=0x01; mess[1]=0x06; mess[2]=0x16; mess[3]=0x00; mess[4]=0x00; mess[5]=0x00; crc = 0xffff; for(i=0; i<=5; i++) { thisbyte = mess[i]; crc = crc ^ thisbyte; for(shift = 0; shift<8;shift++) { lastbit = crc & 0x0001; crc = (crc >> 1) & 0x7fff; if (lastbit ==0x0001) { crc = crc ^ 0xa001; } } } highbyte = (crc >> 8) & 0xff; lowbyte = crc & 0xff; mess[6] = lowbyte; mess[7] = highbyte; printf("%x /n", mess[6],mess[7]); }