BIN() Function - Convert Decimal to Binary Integer

Syntax

BIN(intA,intB{,ERR=lineref})

Description

For BBj-specific information, see the BBj BIN() Function.

The BIN() function converts a decimal into a binary string.

Parameter

Description

intA

Decimal to be converted into a binary string. The left-most bit is considered the "sign" bit. If it is "on" (1), the number is negative. Negative numbers are stored in two's complement (negative binary) notation.

IntB

Length of the binary string, in bytes.

ERR=lineref

Branch to be taken if an error occurs during execution.

Although BIN() returns a signed binary string, an overflow error is issued only if an unsigned overflow occurs. For example, BIN(255,1) and BIN(-1,1) both return $FF$ without an error.

The DEC() function performs the reverse operation of BIN(). However, DEC() always assumes a signed binary value. DEC(BIN(255,1)) returns -1.

Examples

>PRINT HTA(BIN(132,1))
84
>PRINT HTA(BIN(-64,2))
FFC0
>PRINT HTA(BIN(1000,2))
03E8

See Also

Functions - Alphabetical Listing