-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcrc8.cpp
More file actions
29 lines (27 loc) · 726 Bytes
/
crc8.cpp
File metadata and controls
29 lines (27 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "crc8.h"
//-------------------------------------------------------------------------
crc8::crc8(int poly)
{
int n,m;
for(n=0;n<256;n++){
int t=n;
for(m=0;m<8;m++) {
if ((t&0x80)!=0)
t=(t<<1)^poly;
else
t=t<<1;
}
lookup[n]=t;
}
}
//-------------------------------------------------------------------------
uint8_t crc8::calc(uint8_t *data, int len)
{
int n;
uint8_t crc=0;
for(n=0;n<len;n++) {
crc=lookup[crc ^ *data];
data++;
}
return crc;
}