Specifications

Commands - 6
BCD
Numeric Function
SYNTAX: n = BCD(m)
PURPOSE: To return four digits in packed BCD format from a number.
REMARKS: The four BCD digits are stored in the variable n. Each BCD digit is 4–bits and the four BCD digits
are stored in 16–bit form. These are known as packed BCD numbers. One common use is to
convert a count to BCD to send to displays that have BCD inputs.
RELATED: BIN
EXAMPLE: A = 456
PRINT BCD(A)
1110
At first, the answer above appears to be wrong. This is due to the fact that the 4–digit BCD number
has been packed into 16–bits and the print command is treating it as a binary number.
The following converts a 4–digit number and outputs it to two ports:
10 N = BCD(6789)
20 M = N AND 255
30 OUT 1,M
40 N = N \ 256
50 OUT 2,N
ERROR: <Illegal argument> – if m > 9999
<Data negative > – for m