#### BCD

#### Synopsis

    HELP:   Binary coded decimal (BCD) number
    TYPE:   OBJECT
    SYNTAX: BCD(SIGNED,TYPE=UNPACKED/PACKED/ZONED,ZONE=ANY/ASCII/EBCDIC)

#### Description

Reads a binary-coded decimal (BCD) representation of an integer number, where each decimal (base 10) digit is encoded in a 4 or 8 bit value. The result is an FL5-internal neutral integer representation which can be converted to any of the supported target integer representations by a corresponding write converter.

This converter supports multiple formats of BCD numbers. The parameter TYPE must be set to the correct BCD format of the input number. The following formats are supported:

- UNPACKED: Each decimal digit is stored in one byte. Only the lower nibble (4 bits) of each byte is used, the upper nibble is ignored.
- PACKED: Each decimal digit is stored in one nibble, so one byte contains two decimal digits.
- ZONED: Each decimal digit is stored in one byte. The upper nibble contains the zone bits. They are usually set to a fixed value so that the byte holds a character value corresponding to the digit.

BCD numbers can be signed or unsigned. If the SIGNED flag is specified, read numbers are treated as signed. Without the flag, numbers are treated as unsigned BCD. Unsigned BCD numbers can only have positive values. The sign is part of the BCD number. Its specific representation depends on the BCD type:

- UNPACKED: The sign is stored in the right-most byte
- PACKED: The sign is stored in the right-most nibble
- ZONED: The sign is stored in the upper nibble of the right-most byte, replacing the zone bits with the sign value

The hexadecimal values 0xB and 0xD indicate a negative sign. 0xA, 0xC, 0xE and 0xF sign values are treated as positive numbers. Sign values of 0x0 through 0x9 are illegal. For type ZONED, these sign values only apply for BCD numbers in EBCDIC zone format, i.e. the upper zone nibble is set to 0xF. If the zone is in ASCII format (0x3), the positive sign value is 0x3, the negative sign value is 0x7 and all other values are illegal. So, the decimal number -123 in zoned BCD with an EBCDIC zone is 0xF1F2D3. With an ASCII zone, the same number is stored as 0x313273.

The parameter ZONE is relevant only if TYPE=ZONED and specifies whether the zone is in ASCII or EBCDIC format. This is mainly relavant for interpreting the sign correctly as described in the paragraph above. If not specified, the zone is system-dependent (i.e. EBCDIC on EBCDIC machines, ASCII otherwise).

#### Arguments

- `SWITCH: SIGNED - Enable for signed BCD [FALSE]`
- `NUMBER: TYPE=UNPACKED/PACKED/ZONED - BCD type [UNPACKED]`
  - `UNPACKED - Unpacked BCD number`
  - `PACKED - Packed BCD number`
  - `ZONED - Zoned BCD number`
- `NUMBER: ZONE=ANY/ASCII/EBCDIC - Character set (only for type ZONED) [ANY]`
  - `ANY - Any kind of zone format (ASCII and EBCDIC accepted)`
  - `ASCII - ASCII character set (0x30-0x39)`
  - `EBCDIC - EBCDIC character set (0xF0-0xF9)`