Python Glossary Русский

all Python 3binasciifunction

binascii.crc_hqx()

checksums

Computes a 16-bit CRC-CCITT (polynomial 0x1021) starting from value. Used in protocols such as XMODEM, Bluetooth and the old BinHex format.

Syntax

binascii.crc_hqx(data, value)

The initial value is mandatory and decides which 'CRC-16' you get: 0 gives the XMODEM variant, 0xFFFF gives CCITT-FALSE, whose check value for '123456789' is 0x29b1. If a protocol asks for 'CRC-16', confirm the polynomial and initial value: there are dozens of variants, and not all match this function.

Examples

import binascii
print(hex(binascii.crc_hqx(b'123456789', 0xFFFF)))  # → 0x29b1
print(hex(binascii.crc_hqx(b'123456789', 0)))  # → 0x31c3

See also

Open in the full glossarydocs.python.orgReport an inaccuracy