Remote Processing CAMBASIC User Manual
Page 41

Comm ands - 8
BCD
Numeric Fun ction
SYNTAX:
n = B C D (m)
PURPOSE:
To return four digits in packed BCD format from a number.
REMARK S:
The four BCD d igits are stor ed in the var iable n. Each BC D digit is 4– bits and the four BCD d igits
are stor ed in 16– bit form . T hese are known as p acked BC D num bers. One com mon use is to
convert a count to BC D to send to displays that have BCD inputs.
RELATED:
BIN
EXAMPLE:
A = 456
PRINT BCD(A)
1110
A t fi r st , t he a ns w er a b ov e ap p ea r s t o b e wr o n g. T h i s i s d u e t o t he f ac t t ha t t he 4 – d ig it BC D
number has been packed into 16– bits and the print command is treating it as a binary number.
The following conv erts 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