Skip to main content

Module bcd

Module bcd 

Source
Expand description

Binary-coded decimal (BCD) codec for DVB wire fields.

DVB packs many numeric fields as BCD — each 4-bit nibble holds one decimal digit (0–9). Examples: the HHMMSS of a UTC time, the frequency / symbol-rate of the delivery-system descriptors, the HHMM of a local-time offset. These helpers convert between the packed BCD representation and plain integers in both directions so callers never hand-decode nibbles.

Every decode has a symmetric encode; both reject out-of-range input by returning None rather than producing garbage.

Constants§

MAX_NIBBLES
Largest number of BCD nibbles representable in the bcd_to_decimal / decimal_to_bcd u64 carrier.

Functions§

bcd_to_decimal
Decode the low nibbles BCD digits of raw to a decimal value.
decimal_to_bcd
Encode value as nibbles packed-BCD digits in the low bits of a u64.
from_bcd_byte
Decode a packed-BCD byte (two nibbles) to 0..=99.
to_bcd_byte
Encode 0..=99 to a packed-BCD byte.