BCD arithmetic

Name

BCD arithmetic -- BCD arithmetic for Teletext page numbers.

Synopsis



typedef     vbi_bool;
typedef     vbi_pgno;
typedef     vbi_subno;
#define     VBI_ANY_SUBNO
#define     VBI_NO_SUBNO
unsigned int vbi_dec2bcd                    (unsigned int dec);
unsigned int vbi_bcd2dec                    (unsigned int bcd);
unsigned int vbi_add_bcd                    (unsigned int a,
                                             unsigned int b);
vbi_bool    vbi_is_bcd                      (unsigned int bcd);

Description

Teletext page numbers are expressed as 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.

Details

vbi_bool

typedef int vbi_bool;


vbi_pgno

typedef int vbi_pgno;

Teletext or Closed Caption page number. For Teletext pages this is a bcd number in range 0x100 ... 0x8FF. Page numbers containing digits 0xA to 0xF are reserved for various system purposes, these pages are not intended for display.

Closed Caption page numbers between 1 ... 8 correspond to the four Caption and Text channels:

1Caption 1"Primary synchronous caption service [English]"
2Caption 2"Special non-synchronous data that is intended to augment information carried in the program"
3Caption 3"Secondary synchronous caption service, usually second language [Spanish, French]"
4Caption 4"Special non-synchronous data similar to Caption 2"
5Text 1"First text service, data usually not program related"
6Text 2"Second text service, additional data usually not program related [ITV data]"
7Text 3"Additional text channel"
8Text 4"Additional text channel"


vbi_subno

typedef int vbi_subno;

This is the subpage number only applicable to Teletext pages, a BCD number in range 0x00 ... 0x99. On special 'clock' pages (for example listing the current time in different time zones) it can assume values between 0x0000 ... 0x2359 expressing local time. These are not actually subpages.


VBI_ANY_SUBNO

#define VBI_ANY_SUBNO 0x3F7F


VBI_NO_SUBNO

#define VBI_NO_SUBNO 0x3F7F


vbi_dec2bcd ()

unsigned int vbi_dec2bcd                    (unsigned int dec);

Converts a decimal number between 0 ... 999 to a bcd number in range number 0x000 ... 0x999. Extra digits in the input will be discarded.

dec: Decimal number.
Returns :BCD number.


vbi_bcd2dec ()

unsigned int vbi_bcd2dec                    (unsigned int bcd);

Converts a bcd number between 0x000 ... 0xFFF to a decimal number in range 0 ... 999. Extra digits in the input will be discarded.

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


vbi_add_bcd ()

unsigned int vbi_add_bcd                    (unsigned int a,
                                             unsigned int b);

Adds two bcd numbers, returning a bcd sum. The result will be in range 0x00000000 ... 0xFFFFFFFF, discarding carry and extra digits in the inputs. To subtract you can add the two's complement, e. g. -0x1 = +0x99999999.

a: BCD number.
b: BCD number.
Returns :BCD number. The result is undefined when the bcd number contains hex digits 0xA ... 0xF.


vbi_is_bcd ()

vbi_bool    vbi_is_bcd                      (unsigned int bcd);

Tests if bcd forms a valid BCD number.

bcd: BCD number.
Returns :FALSE if bcd contains hex digits 0xA ... 0xF.