wer kann mir mal diese pythonroutine umsetzen in eine normale basicprocedur.
ich benutze purebasic.
danke.
gruss
Code: Alles auswählen
def calculate_checksum(block):
"""
Calculate the checksum for a 256 bytes block
"""
# Constants
SEED_CRC = 0xFFFF # Seed for CRC
MASK_CRC = 0x1021 # Mask of CRC-16-CCITT (ISO 3309 / x^16 + x^12 + x^5 + 1)
crc_tmp = SEED_CRC # Initialize CRC
for i in block:
crc_tmp = crc_tmp ^ (ord(i) << 8)
for j in range(8):
if (crc_tmp & 0x8000):
crc_tmp = (crc_tmp << 1) ^ MASK_CRC
else:
crc_tmp = crc_tmp << 1
crc_tmp = (crc_tmp & 0xFFFF) ^ 0xFFFF # Make the CRC ones' complement
return chr(crc_tmp // 256) + chr(crc_tmp % 256)