Skip to content

BIN

Binary

This string function converts an integer into its equivalent binary data.

BIN (numeric-value, result-length [,ERR=line-ref|,ERC=error-code])
numeric-value
is an integer that ranges from 0 through +/-.99999999999999E+141.
result-length
is an integer from 1 through 32600 that specifies the length in bytes of the result.
line-ref
is the program line number or label to branch to if an error is produced by this function.
error-code
is a programmer-defined error code. Valid values are positive or negative whole numbers.

This function converts a signed or unsigned integer into its binary code equivalent, right-justified, sign-extended, in the number of bytes indicated.

The reverse of this function is the DEC Function, which converts binary data into its integer equivalent.

The BIN Function cannot operate on fractional numbers, but can operate on negative numbers. Negative numbers are converted to their twos-complement form.

You can specify more bytes in the result-length than necessary; any extra bytes have the sign extended. For positive numbers, the excess bytes carry zero bits ($00$); for negative numbers, the excess bytes carry one bit ($FF$). For example:

HTA(BIN(65,3))=$000041$
HTA(BIN(-65,3))=$FFFFBF$.

It takes only 59 bytes to contain the largest possible numeric-value that can be expressed in Thoroughbred Basic whether numeric-value is negative or positive.

If numeric-value is not an integer, an ERR=26 results.

If result-length is greater than 32600 or less than 1, an ERR=41 results.

If the result-length is too small to contain the binary code representation of numeric-value, an ERR=40 results.

BIN (65,1)

returns the ASCII character for an “A”, which is the hexadecimal code $41$ or the binary code 0100 0001.

LET X$ = BIN (X,1)

If X=65, this statement returns the same value as above and assigns it to X$.

BIN (16706,2)

returns the ASCII characters for “AB”, which is the hexadecimal code $4142$ or the binary code 0100 0001 0100 0010.

DEC function

From the Thoroughbred Basic Language Reference, Volume I: A–E, version 8.9.1. Open this page in the PDF