Skip to content

Register

A straightforward, bit by bit CRC register. Use it when you need full control over the calculation, e.g. to process data incrementally.

from crc import Crc8, Register

register = Register(Crc8.CCITT)

register.init()
register.update(bytes([0, 1, 2, 3, 4, 5]))
assert register.digest() == 0xBC

Tip

For most use cases the Calculator is the more convenient choice. If you need speed, use TableBasedRegister. See raw registers for a guide.

Bases: BasicRegister

Simple crc register, which will process one bit at the time.

Note

If performance is an important issue for the crc calculation use a table based register.

__getitem__(index)

Gets a single byte of the register.

Parameters:

Name Type Description Default
index int

byte which shall be returned.

required

Returns:

Type Description
int

The byte at the specified index.

Raises:

Type Description
IndexError

Invalid index for this register.

__init__(configuration)

Create a new BasicRegister.

Parameters:

Name Type Description Default
configuration Configuration

Used to configure the crc algorithm.

required

__len__()

Returns:

Type Description
int

The width of the register.

digest()

See AbstractRegister.digest

init()

See AbstractRegister.init

reverse()

See AbstractRegister.digest

update(data)

See AbstractRegister.update