Hello!
I have to write a small program in C for work.
The main block of this program is a function that calculate the modbus checksum, but is written in python.
Is prossibile to convert it in C?
Code:
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
msb = crc >> 8
lsb = crc & 0x00FF
return '{:X}{:X}'.format(lsb, msb)
print crc16('11010003000C')
There is an online converter or something similar?