BitDtoB


The BitDtoB function converts a decimal number to a binary string representation.

Syntax

sBinary = BitDtoB( nNumber )

where

    sBinary is the binary string representation.

    nNumber is the decimal number to convert.

  

The conversion is returned with all characters present, including leading 0's. For example, the binary representation of a 32-bit integer will always be returned using 32 characters even if most of the high-order bits are 0. To reduce the string length, you can use the BitTrim function to strip all leading 0's from the binary string.

Example

The following script converts a decimal number to a binary string representation. Note that the decimal number is printed using %u because it is considered an unsigned (i.e., 0 or positive) integer.

n = 15

-- pick a number

s = BitDtoB( n )

-- convert to a binary string

Printf( "'%u --> %s'", n, s )

-- prints 15 --> 00000000000000000000000000001111

Printf( "'%u --> %s'", n, BitTrim(s) )

-- prints 15 --> 1111

Related Topics

Boolean Math Functions

BitBtoD

BitDtoX