BitTest


The BitTest function determines if a specified bit position is set in a number.

Syntax

nResult = BitTest( nNumber, nPos )

bullet.gif    nResult is 1 if the bit at nPos is set or 0 if it is not set.

bullet.gif    nNumber is the number to test.

bullet.gif    nPos is the bit position, beginning at position 1 for the lowest order bit.

Remarks

The BitTest function returns a 1 if the target bit position is set to 1 in the number. For example, 23 decimal equals 16 + 7, or 10111 binary. The bit at position 5 is set, therefore BitTest( 23, 5 ) gives the result 1. Conversely, the bit at position 4 is not set, so BitTest( 23, 4 ) gives the result 0.

Example

The following script tests if a bit is set to 1 in a number.

nNum = 23 nPos = 5

-- pick two numbers

Printf( "'%d'", BitTest( nNum, nPos ) )

-- prints the result 1 because the 5th bit is set.

Related Topics

Boolean Math Functions

BitAnd


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