[Tutor] CRC calculation with python

Chris Calloway cbc at unc.edu
Tue Feb 6 18:10:36 CET 2007


First, you need to find the preprocessor define for CCITT_POLY. The code 
is incomplete without it.

Second, where did this code come from? It defines an unused local named 
cval, which will usually cause at least a compilation warning.

This looks like a snippet, not a complete CCITT CRC calculation.

-- 
Sincerely,

Chris Calloway
http://www.seacoos.org
office: 332 Chapman Hall   phone: (919) 962-4323
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599

Johan Geldenhuys wrote:
> Hi all,
>  
> I'm not a C++ expert at all and I would like to find out if somebody can 
> explain to me how the statement below can be done in Python?
>  
> """
> _uint16 ComCRC16(_uint8 val, _uint16 crc)
> {
>         _uint8 i;
>         _uint16 cval;
>  
>     for (i=0;i<8;i++)
>     {
>         if (((crc & 0x0001)^(val & 0x0001))!= 0)   crc = (crc >> 1)^ 
> CCITT_POLY;
>         else   crc >>= 1;
>         val >>= 1;
>     }
>     return crc
> }
>  
> """



More information about the Tutor mailing list