On 01/02/11 01:56, Philip Pemberton wrote: > I've spent all day hacking away on an implementation of the > shift-register ECC engine on the WD1100, but it isn't matching up, no > matter what I do... Well, isn't *this* interesting... the NSC appnote seems to be wrong. philpem@cheetah:~/dev/mt-poly-search $ ./mt-poly-search 4 running 4 crcscan threads, using EXHAUSTIVE_SEARCH method HIT: found polynomial match, 0x140A0445 HIT: found polynomial match, 0x4FE4A171 So the NSC appnote seems to have the wrong binary representation=20 specified for the polynomial. Let's look at these in a bitwise form: 140A0443 =3D 0b00010100 00001010 00000100 01000011 (from appnote) 140A0445 =3D 0b00010100 00001010 00000100 01000101 ^^ Working backwards from the polynomial using SpeedCrunch: x=3D2 x=3D2 hex(x^32 + x^28 + x^26 + x^19 + x^17 + x^10 + x^6 + x^2 + 1) 0x1140A0445 Ho hum. I've just wasted a day of debugging because an appnote author=20 couldn't count. C'est la vie! And now the code: uint32_t POLY =3D 0x140A0445; uint32_t crc32(uint32_t initval, unsigned char * data, size_t len) { uint32_t crc =3D initval; size_t i =3D 0; while (i < len) { unsigned char x =3D data[i++]; crc ^=3D (x << (32-8)); for (int j=3D0; j<8; j++) { if (crc & 0x80000000) crc =3D (crc << 1) ^ POLY; else crc =3D crc << 1; } } return crc; } --=20 Phil. piclist@philpem.me.uk http://www.philpem.me.uk/ --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .