BCD arithmetic for Teletext page numbers
High Level Decoding

## Macros

#define | vbi_bin2bcd(n)
#define | vbi_bcd2bin(n)

## Functions

_vbi_inline unsigned int | vbi_dec2bcd (unsigned int dec)
_vbi_inline unsigned int | vbi_bcd2dec (unsigned int bcd)
_vbi_inline unsigned int | vbi_add_bcd (unsigned int a, unsigned int b)
_vbi_inline vbi_bool | vbi_is_bcd (unsigned int bcd)
_vbi_inline vbi_bool | vbi_bcd_digits_greater (unsigned int bcd, unsigned int maximum)

## Detailed Description

Teletext page numbers are expressed as packed binary coded decimal numbers in range 0x100 to 0x8FF. The bcd format encodes one decimal digit in every hex nibble (four bits) of the number. Page numbers containing digits 0xA to 0xF are reserved for various system purposes and not intended for display.

## Macro Definition Documentation

## vbi_bin2bcd

#define vbi_bin2bcd | ( |  | n | ) |

Value:
vbi_dec2bcd(n)
vbi_dec2bcd
_vbi_inline unsigned int vbi_dec2bcd(unsigned int dec)
Definition bcd.h:109

Since
  0.2.28

## vbi_bcd2bin

#define vbi_bcd2bin | ( |  | n | ) |

Value:
vbi_bcd2dec(n)
vbi_bcd2dec
_vbi_inline unsigned int vbi_bcd2dec(unsigned int bcd)
Definition bcd.h:133

Since
  0.2.28

## Function Documentation

## vbi_dec2bcd()

_vbi_inline unsigned int vbi_dec2bcd | ( | unsigned int | dec | ) |

Parameters

  dec | Decimal number.

Converts a two's complement binary between 0 ... 999 to a packed bcd number in range 0x000 ... 0x999. Extra digits in the input will be discarded.

Returns
  BCD number.

## vbi_bcd2dec()

_vbi_inline unsigned int vbi_bcd2dec | ( | unsigned int | bcd | ) |

Parameters

  bcd | BCD number.

Converts a packed bcd number between 0x000 ... 0xFFF to a two's complement binary in range 0 ... 999. Extra digits in the input will be discarded.

Returns
  Decimal number. The result is undefined when the bcd number contains hex digits 0xA ... 0xF.

## vbi_add_bcd()

_vbi_inline unsigned int vbi_add_bcd | ( | unsigned int | a,
|  | unsigned int | b )

Parameters

  a | BCD number.
  b | BCD number.

Adds two packed bcd numbers, returning a packed bcd sum. Arguments and result are in range 0xF000 0000 ... 0x0999 9999, that is -10**7 ... +10**7 - 1 in decimal notation. To subtract you can add the 10's complement, e. g. -1 = 0xF999 9999.

Returns
  Packed bcd number. The result is undefined when any of the arguments contain hex digits 0xA ... 0xF.

## vbi_is_bcd()

_vbi_inline vbi_bool vbi_is_bcd | ( | unsigned int | bcd | ) |

Parameters

  bcd | BCD number.

Tests if bcd forms a valid BCD number. The argument must be in range 0x0000 0000 ... 0x0999 9999.

Returns
  `FALSE` if bcd contains hex digits 0xA ... 0xF.

Referenced by vbi_decode_teletext_8301_local_time().

## vbi_bcd_digits_greater()

_vbi_inline vbi_bool vbi_bcd_digits_greater | ( | unsigned int | bcd,
|  | unsigned int | maximum )

Parameters

  bcd | Unsigned BCD number.
  maximum | Unsigned maximum value.

Compares an unsigned packed bcd number digit-wise against a maximum value, for example 0x295959. maximum can contain digits 0x0 ... 0xF.

Returns
  `TRUE` if any digit of bcd is greater than the corresponding digit of maximum.

Since
  0.2.28