BCD

Synopsis

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

Description

Reads a binary-coded decimal (BCD) representation of a fixed-point number, where each decimal (base 10) digit is encoded in a 4 or 8 bit value. The result is an FL5-internal neutral real number representation which can be converted to any of the supported target real number 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:

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:

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.45 in zoned BCD with two fraction digits and an EBCDIC zone is 0xF1F2F3F4D5. With an ASCII zone, the same number is stored as 0x3132333475.

The FRACDIGITS parameter greatly influences how the BCD value is interpreted. It specifies the number of digits which form the fractional part of the fixed-point number. Fractional digits are always located at the end of the BCD number. In the example above, FRACDIGITS must be set to 2 to interpret the fixed-point BCD number as decimal number -123.45. If the parameter is not specified, it is equivalent to FRACDIGITS=0, i.e. there are no fractional digits.

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