CRC CCITT UPDATE in Python

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Apr 4 20:24:33 EDT 2007


En Sun, 01 Apr 2007 10:10:04 -0300, [Py Thorneiro] <pythoneiro at gmail.com>  
escribió:

[Py Thorneiro]
>> > uint16_t
>> > crc_ccitt_update (uint16_t crc, uint8_t data)
>> > {
>> >    data ˆ= lo8 (crc);
>> >    data ˆ= data << 4;
>> >    return ((((uint16_t)data << 8) | hi8 (crc)) ˆ (uint8_t)(data >> 4)
>> > ˆ ((uint16_t)data << 3));
>> > }

[Martin v. Löwis]
>> Most likely, lo8(crc) == crc & 0xFF, and hi8(crc) == (crc >> 8) & 0xFF
>> (the last bit masking might be redundant, as crc should not occupy more
>> than 16 bits, anyway).

[Py Thorneiro]
>       Please, could you help me? :-) How to port this hi8 and lo8 to  
> Python,
> is there some function similar?

That's exactly what MvL said. To put it more clearly:

def lo8(i16):
   return i16 & 0xff

def hi8(i16):
   return (i16 >> 8) & 0xff

-- 
Gabriel Genellina




More information about the Python-list mailing list