AND

The AND operator is used to perform a logical conjunction of two numbers.

Syntax

result = A AND B

Remarks

The AND operator converts A and B into integers and performs a bit-wise comparison of identically positioned bits and sets the corresponding bit in result according to the following truth table:

If bit in              And bit in         The result

A is                   B is                  is

0                       0                      0

0                       1                      0

1                       0                      0

1                       1                      1

Although AND is a bit-wise operator, it is often used to test Boolean (True/False) conditions. 0 is false and any non-zero number is true. Because AND is a bit-wise operation, it is possible to AND two non-zero numbers (e.g., 2 and 4) and get 0. The binary representation of -1 has all bits equal 1. That is, any number AND -1 returns the original number. That is why the predefined constant True = -1.

If, and only if, both expressions evaluate True, result is True. If either expression evaluates False, then result is False. The following table illustrates how result is determined:

If A                 AND B                 The result

is                   is                        is

-1                   Any number         Number2

-1                   NAN                    NAN

0                    Any number         0

0                    NAN                    NAN

NAN = Not a number

Expressions can be used in place of one or both of the numbers. Comparison expressions evaluate as True (-1) or False (0).