Main Page   Modules   Data Structures   Data Fields   Related Pages   Examples  

BCD arithmetic for Teletext page numbers


Defines

#define vbi_bin2bcd(n)   vbi_dec2bcd(n)
#define vbi_bcd2bin(n)   vbi_bcd2dec(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.

Define Documentation

#define vbi_bin2bcd( n )   vbi_dec2bcd(n)
 

Since:
0.2.28

#define vbi_bcd2bin( n )   vbi_bcd2dec(n)
 

Since:
0.2.28


Function Documentation

_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_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_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_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.

_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


Generated at Tue Feb 26 01:33:09 2008 for ZVBI Library by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001