mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added update() helper
This commit is contained in:
parent
afc3c0ae61
commit
479f5e0220
1 changed files with 7 additions and 3 deletions
10
crc.hh
10
crc.hh
|
|
@ -15,13 +15,18 @@ class CRC
|
|||
TYPE lut[256];
|
||||
TYPE poly;
|
||||
TYPE crc;
|
||||
TYPE update(TYPE prev, bool data)
|
||||
{
|
||||
TYPE tmp = prev ^ data;
|
||||
return (prev >> 1) ^ ((tmp & 1) * poly);
|
||||
}
|
||||
public:
|
||||
CRC(TYPE poly, TYPE crc = 0) : poly(poly), crc(crc)
|
||||
{
|
||||
for (int j = 0; j < 256; ++j) {
|
||||
TYPE tmp = j;
|
||||
for (int i = 8; i; --i)
|
||||
tmp = (tmp >> 1) ^ ((tmp & 1) * poly);
|
||||
tmp = update(tmp, 0);
|
||||
lut[j] = tmp;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,8 +40,7 @@ public:
|
|||
}
|
||||
TYPE operator()(bool data)
|
||||
{
|
||||
TYPE tmp = crc ^ data;
|
||||
return crc = (crc >> 1) ^ ((tmp & 1) * poly);
|
||||
return crc = update(crc, data);
|
||||
}
|
||||
TYPE operator()(uint8_t data)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue