BitTrim


The BitTrim function removes leading zero's from the binary or hexadecimal string representation of a number.

Syntax

sResult = BitTrim( sString )

bullet.gif    sResult is the trimmed string

bullet.gif    sString is the string to be trimmed.

Remarks

Hexadecimal and binary representations of numbers can have a long string of leading 0's. This function trims all leadingh 0's to make the number more manageable. For example, the decimal number 33 has only the bits at position 6 and 1 set, so its binary representation is 00000000000000000000000000100001. Using BitTrim(), the binary representation becomes 100001.

Example

The following script trims the leading zero's from the binary result of a BitOr operation on 2 small numbers. The script uses the BitDtoB function to convert the decimal result of the OR operation to a binary string representation.

n1 = 7 n2 = 18

-- pick 2 numbers

s = BitDtoB( BitOr( n1, n2 ) )

-- compute the OR and convert to a binary string

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

-- prints 00000000000000000000000000010111 --> 10111

Related Topics

Boolean Math Functions


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