111,097
社区成员




public int CRC7_Cal(byte[] buffer,int cnt)
{
int CRC7 =0xE5; //x7+x6+x5+x2+1
int count = 0;
int temp1 = 0;
int temp2 = 0;
int crc = buffer[0];
count = 8;
//CRC校验
while (count < cnt * 8)
{
temp1 = crc & 0x80; //移除最高位0
while (0 == temp1)
{
crc = (crc << 1) & 0xfe;
temp2 = buffer[count / 8];
temp2 = (temp2 >> (7 - (count % 8))) & 0x01;
crc = crc | temp2;
temp1 = crc & 0x80;
count++;
if (count == cnt * 8) break;
}
if ((count == cnt * 8) && (0 == temp1)) break;
crc = crc ^ CRC7;
}
return crc;
}