comnum.Crc#

class comnum.Crc(name)#

A cyclic redundancy check of 5G NR (3GPP TS 38.212, Sec. 5.1).

Parameters:

name (str) – "crc24a", "crc24b", "crc24c", "crc16", "crc11" or "crc6".

Raises:

ValueError – for an invalid parameter (the message names it).

Examples

>>> import comnum, numpy as np
>>> crc = comnum.Crc("crc24a")
>>> w = crc.attach(np.array([1, 0, 1, 1], dtype=np.uint8))
>>> bool(crc.check(w)), w.size
(True, 28)
attach(bits)#

A message followed by its parity bits.

Parameters:

bits (array_like) – the message.

Returns:

the message and the width parity bits (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for bits that are not 0 or 1, or not a 1-D array.

check(word)#

Whether a word passes the check.

Parameters:

word (array_like) – information then parity bits.

Returns:

whether the parity bits match.

Return type:

bool

Raises:

ValueError – for bits that are not 0 or 1, or not a 1-D array.

checksum(bits)#

The parity bits of a message.

Parameters:

bits (array_like) – the message.

Returns:

width parity bits (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for bits that are not 0 or 1, or not a 1-D array.

width#

Degree of the polynomial (number of parity bits).

Type:

int