Bitwise AND '&', '&='

The Bitwise AND operator performs a bitwise AND of the bits of the first operand with the bits of the second operand. Bitwise AND can be used in both variable and integer constant expressions, but not in floating-point constant expressions. 

Each bit of the two operands is subject to the following logic:

Bitwise AND Truth Table
ABResult
000
010
100
111

Example:

X := %00101100 & %00001111

The above example ANDs %00101100 with %00001111 and writes the result, %00001100, to X.

Bitwise AND has an assignment form, &=, that uses the variable to its left as both the first operand and the result destination. For example,

X &= $F      'Short form of X := X & $F

Here, the value of X is ANDed with $F and the result is stored back in X. The assignment form of Bitwise AND may also be used within expressions for intermediate results; see Intermediate Assignments.

Be careful not to get Bitwise AND '&' confused with Boolean AND 'AND'. Bitwise AND is for bit manipulation while Boolean AND is for comparison purposes (see Boolean AND 'AND', 'AND=').

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.