Purpose 
Set or reset a bit in an

Syntax 
BIT CALC intvar, bitnumber, calcexpr 
Remarks 
BIT CALC performs like a combination of the BIT SET and BIT RESET statements, offering the choice between set (1) and reset (0) according to the result of a numeric expression. 
intvar 
An integral class variable (Byte, Word, Doubleword, Integer, Longinteger or Quadinteger), or a variable forming the base of an implied bitarray. 
bitnumber 
An integral class expression or numeric literal that specifies the bit number to adjust. Bit numbers start from zero (0), and extend to the size of the target variable or bitarray. For example, a 16bit integer variable uses the range 0 to 15. An implied bitarray comprised of a Longinteger array with 100 elements (4 bytes * 100 = 400 bytes = 3200 bits) covers the bit range 0 to 3199. 
calcexpr 
The value derived from bit zero of calcexpr determines the set or reset action. If bit zero contains a zero (0), the bit in intvar is reset; if bit zero in calcexpr contains a one (1), the bit in intvar is set. This action can be more easily remembered if we consider PowerBASIC performs an implied bitwise AND operation (calcexpr AND 1) to derive the set or reset action. 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 16bit scalar variable may trigger a General Protection Fault (GPF). Similarly, adjusting the 4097th bit of a bitarray derived from a 128element DWORD array may cause similar problems. bitnumber is always zerobased, so the 129th bit of an implied bitarray is referenced in the BIT statement with bitnumber equal to 128. For example: x& = BIT(A?(1), 128). The first bit is the leastsignificant bit, which is bit number zero. For example: 
See also 

Example 
DIM dwStatus1 AS DWORD DIM dwStatus2 AS DWORD DIM iBit AS INTEGER DIM sResult1 AS STRING DIM sResult2 AS STRING
FOR iBit = 0 TO 31 BIT CALC dwStatus1, iBit, RND(0,1) BIT CALC dwStatus2, iBit, iBit MOD 3 NEXT iBit sResult1 = BIN$(dwStatus1,32) sResult2 = BIN$(dwStatus2,32) 
Result 
sResult1 = "01001101001110101110111010010101" sResult2 = "10010010010010010010010010010010" 