ByteToBin

Syntax:

    stringvar = ByteToBin(bytevar)

Command Availability:

Available on all microcontrollers.

Explanation:

The ByteToBin function creates a string of ANSI characters representing a byte’s binary value. It converts a number into an 8-character string consisting of ones and zeros.

Note: Supports Byte variables only. For Word variables, use WordToBin.

Example:

    string = ByteToBin( 1 )   ' Returns "00000001"          ' <<< the ByteToBin instruction

    string = ByteToBin( 254 ) ' Returns "11111110"

Key line: ByteToBin( 1 ) — returns the 8-character string "00000001", the binary representation of the byte value 1, padded with leading zeros to a fixed width.

See Also:

  • WordToBin — the equivalent conversion for Word variables
  • ByteToHex — converting a byte to hexadecimal instead of binary