方法一:
buf[]传入字节,index起始位,bytetotal要校验的长度。
int xor16(unsigned char buf[], int index, long bytetotal)
{
// unsigned char buff = 0;
int buff=0;
int i;
for (i = index; i <bytetotal; i++) {
buff = buff^(int)buf[i];
}
return buff;
}
方法二:
unsigned char calc_lrc2(unsigned char* data, int data_len) { unsigned char lrc = 0; for (int i = 0; i < data_len; i++) { lrc ^= data[i]; printf("%02X\n",lrc); } return lrc; }