BitTest
The BitTest function determines if a specified bit position is set in a number.
nResult = BitTest( nNumber, nPos ) |
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.
The following script tests if a bit is set to 1 in a number.
|
-- pick two numbers |
|
-- prints the result 1 because the 5th bit is set. |