Remote Processing CAMBASIC User Manual

Page 43

Advertising
background image

Comm ands - 10

BIN$

String Function

SYNTAX:

n$ = BIN$(m)

PURPOSE:

Returns an 8– bit binary representation of a number.

REMARK S:

The most significant bit (bit 7) is on the left and the least significant is on the right. If a string
argument is inadvertently used, the result will be zero.

This function is primarily used with the INP function to display the status of each input line.

RELATED:

The HE X$ function and the “@” binary prefix.

EXAMPLE:

PRINT BIN$(199)

11000111

This example illustrates the usefulness of BIN$ to determine the status of an I/O port. Suppose that
the port is connected to switches. Reading the value with the INP function yields 199. Without
doing calcula tions, it is difficult to tell which sw itches are on. Using BIN $ you can see imme diately
that switches 0, 1, 2, 6 and 7 are on.

ERROR:

< Type mismatch> – if m is a string or n is not a string.
< Data > 255> – for m.
< Data negative > – for m.

Advertising