BIT function


Return the value of a particular bit in an integral class variable (or in an implied bit-array)


flag = BIT(intvar, bitnumber)


The BIT function is used to determine the value of one particular bit in an integral-class variable or implied bit-array.


The parameter intvar must be a variable, not an expression.  The BIT function returns either 0 or 1 to indicate the value of the specified bit.


The bit in question.  The allowable range for the parameter is the same as that of a Long-integer.  This makes it possible to have implicit bit-arrays of more than 2 billion bits in size.  For such arrays, bits 0 to 15 are in the first word starting at intvar, bits 16-31 are in the next word, and so forth.

Implied bit-arrays are considered to start at the memory position of the variable intvar.  For example, if intvar is itself an array variable, it is possible to access bits in any of the following elements of the array.  See the array examples below.

Care must be exercised to ensure that the bit index number (bitnumber) does not exceed the number of bits that can be validly accessed.  For example, reading the 17th bit of a 16-bit scalar variable may trigger a General Protection Fault (GPF).  Similarly, adjusting the 4097th bit of a bit-array derived from a 128-element DWORD array may cause similar problems.  bitnumber is always zero-based, so the 129th bit of an implied bit-array is referenced in the BIT statement with bitnumber equal to 128.  For example: x& = BIT(A?(1), 128).

The first bit is the least-significant bit, which is bit number zero.  For example:

See also

BIT CALC statementBIT statement, BITS functions


x% = 7

y% = BIT(x%, 2)


DIM z%(1:2000000)  ' 32 million element bit-array

y% = BIT(z%(1),16) ' bit 0 of 2nd word of z%()

y% = BIT(z%(2000000),15)   ' MSB of last element

y% = BIT(z%(1), 31999999&) ' MSB of last element