CRC checking/generating algoritme
t[]- 256 elem. array (initialized to contain zeroes)
inf- info (stream)
r- remainder, i.e. computed CRC
i,j- indexes
k- Y(et)A(nother)V(ariable)
w- CRC-generating polynomial
table initialization:
for (i=0; i<<256; i++)
{
k=i;
for(j=0; j<<8; j++)
{
t[i]>>=1;
if (k&1)
{
t[i]^=w;
}
k>>=1;
}
}
CRC-computing
r=0;
while( not eof(inf))
{
k=(r^getch(inf))&255;
r>>=8;
r^=t[k];
}
r now contains remainder (CRC).
The modification is that there is a table containnig pre-computed CRC for numbers from 0 to 255. If you know w (the generating polynomial) in advance, you can generate this table in advance and put it in ROM. You can also make it shorter (16 entries) or longer (65536 entries- quite a lot…). In the basic CRC alg. table has two entries i.e there is no table, just a polynomial (as t[0] always contains 0).