How to calculate CRC value in python?

Hi Folks,

After a long while I’ve found a new solution for CRC calculation in python. For example, if you give input ‘010300000002’ then returned output value will be ‘C40B’ or ‘0xC40xB’

I hope that It will help you folks.

def crc16(data, bits=8):
    crc = 0xFFFF
    for op, code in zip(data[0::2], data[1::2]):
        crc = crc ^ int(op+code, 16)
        for bit in range(0, bits):
            if (crc&0x0001)  == 0x0001:
                crc = ((crc >> 1) ^ 0xA001)
            else:
                crc = crc >> 1
    return typecasting(crc)

def typecasting(crc):
    msb = hex(crc >> 8)
    lsb = hex(crc & 0x00FF)
    return lsb + msb

 


Django-Python Web based application developer.

Share This Post

Related Articles

2 Responses to “How to calculate CRC value in python?”

  1. crc failed says:

    I really do trust each of the aspects you have displayed for ones submit. They can be extremely effective and may surely get the job done. Nevertheless, the threads are far too easy to start. May you please lengthen these individuals somewhat by when? Just article.

  2. dani says:

    Definitely consider that that you said. Your favourite justification appeared to be on the internet the simplest factor to take into accout of. I say to you, I definitely get irked even as people consider concerns that they just do not know about. You managed to hit the nail upon the top and also outlined out the entire thing without having side-effects , folks could take a signal. Will likely be back to get more. Thank you

Leave a Reply

© 2017 Techy Diary. All rights reserved.
Powered by Charvi Groups