1
byte
crc8(
byte
[] buffer,
int
len)
2 {
3 byte crc, i, j;
4 crc = 0 ;
5
6 for (j = 0 ; j < len; j ++ )
7 {
8 for (i = 0x01 ; i != 0 ; i <<= 1 )
9 {
10 if (((crc & 0x01 ) ^ (buffer[j] & i)) == 1 )
11 {
12 crc ^= 0x18 ;
13 crc >>= 1 ;
14 crc |= 0x80 ;
15 }
16 else
17 crc = ( byte )(crc >> 1 );
18 }
19 }
20 return crc;
21 }
22 byte crc8( byte [] buffer)
23 {
24 return crc8(buffer, buffer.Length);
25 }
2 {
3 byte crc, i, j;
4 crc = 0 ;
5
6 for (j = 0 ; j < len; j ++ )
7 {
8 for (i = 0x01 ; i != 0 ; i <<= 1 )
9 {
10 if (((crc & 0x01 ) ^ (buffer[j] & i)) == 1 )
11 {
12 crc ^= 0x18 ;
13 crc >>= 1 ;
14 crc |= 0x80 ;
15 }
16 else
17 crc = ( byte )(crc >> 1 );
18 }
19 }
20 return crc;
21 }
22 byte crc8( byte [] buffer)
23 {
24 return crc8(buffer, buffer.Length);
25 }
这里有一个查表实现的算法
http://www.cnblogs.com/canny/archive/2004/12/27/82468.aspx