BitDtoB


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

Syntax

sBinary = BitDtoB( nNumber )

bullet.gif    sBinary is the binary string representation.

bullet.gif    nNumber is the decimal number to convert.

Remarks

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


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.