BitNor BitDtoX

BitTest


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

Syntax

nResult = BitTest( nNumber, nPos )

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