AND operator

Purpose | The AND operator works as both a logical and a bitwise arithmetic operator.

Syntax

p AND q

Using AND as a logical operator

AND returns TRUE (non-zero) if (and only if) both its operands are TRUE. The AND truth table looks like this:

Truth Table
x | y | x AND y
T | T | T
T | F | F
F | T | F
F | F | F

Using AND as a bitwise arithmetic operator

AND masks clear selected bits of an integral-class value without affecting the other bits. For example, to clear the most-significant (leftmost) 2 bits in the integer value &H9700, AND it with &H3FFF. That is, the mask contains all 1s, except for the bit positions you want to force to 0:

See also | Arithmetic Operators, EQV, IMP, ISFALSE, ISTRUE, NOT, OR, XOR