LongToBin

Syntax:

    stringvar = LongToBin(longvar)

Command Availability:

Available on all microcontrollers.

Explanation:

The LongToBin function creates a string of ANSI characters representing a Long’s binary value. It converts a number into a 32-character string consisting of ones and zeros.

Note: Supports Long variables only. For Byte variables use ByteToBin, for Word variables use WordToBin, and for Integer variables use IntegerToBin.

Example:

    string = LongToBin( 1 )   ' Returns "00000000000000000000000000000001"          ' <<< the LongToBin instruction

    string = LongToBin( 254 ) ' Returns "00000000000000000000000011111110"

Key line: LongToBin( 1 ) — returns a fixed 32-character binary string, since a Long occupies 4 bytes (32 bits) of storage.

See Also: