CRC CCITT UPDATE in Python

P

pythoneiro

Please,

Please, is there here some good soul that understand this
functions hi8 and lo8 (from GCC AVR) and can help me to port it to
Python?

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));
}

Source: http://tldp.tuxhilfe.de/linuxfocus/common/src2/article352/avr-libc-user-manual-1.0.4.pdf

Reason, I would like to code in Python one simulator from one
code C++ AVR

Thanks.,

../Fã -Py -Thorneiro
 
G

Guest

Please, is there here some good soul that understand this
functions hi8 and lo8 (from GCC AVR) and can help me to port it to
Python?

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));
}

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).

HTH,
Martin
 
G

Gabriel Genellina

En Sun, 01 Apr 2007 10:10:04 -0300, [Py Thorneiro] <[email protected]>
escribió:

[Py Thorneiro]
[Martin v. Löwis]
[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top