Remote Processing CAMBASIC User Manual

Page 42

Advertising
background image

Comm ands - 9

BIN

Numeric Fun ction

SYNTAX:

n = B IN (m)

PURPOSE:

To return a number from a packed BCD number.

REMARK S:

This function assumes that the BCD digits are packed. That is, there are four BCD digits per
16– bits.

EXAMPLE:

A = BIN(B)

Norm ally, the only way BCD data can enter the system is through an I/ O port like those on the
82C55 (e. g. reading a two digit BCD thum b wheel switch).

Each of the two switches has four outputs. Together, the eight lines are connected to an I/O port
input. Assuming the thumb wheel switches are set to 98 and connected to I/O port &18, the port
input would look as follows (where D0 through D7 are the eight data bits):

D 7

D 6

D 5

D 4

D 3

D 2

D 1

D 0

1

0

0

1

1

0

0

0

The example below appears wrong at first. However, CAMBASIC assumed that this was a binary
numbe r and ga ve you the de cimal equ ivalent.

PRINT INP(&18)
152

To get the c orre ct result:

PRINT BIN(INP(&18))
98

ERROR:

< Illegal arg ument> – if any BCD digit > 9
< Data negative > – for m

Advertising