AND

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

Syntax

result = Number1 AND Number2

Remarks

The AND operator performs a bit-wise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following truth table:

If bit in Number1 is And bit in Number2 is The result is
0 0 0
0 1 0
1 0 0
1 1 1

Bit-wise operations are performed on integers; floating point values will first be converted before the bit-wise operation is performed. Although AND is a bit-wise operator, it is often used to test Boolean (True/False) conditions. Boolean values are implemented as Longs that are restricted to -1 (True) or 0 (False). Any non-zero number >= 1 will evaluate as true (a float value between .999 and 0 when converted to a Long is 0). Because AND is a bit-wise operation, it is possible to AND two non-zero numbers (for example, 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 Number 1 is AND Number2 is The result is
-1 Any number Number2
-1 ClosedNAN Not a number. A data word indicating a measurement or processing error. Voltage overrange, SDI-12 sensor error, and undefined mathematical results can produce NAN. NAN
0 Any number 0
0 NAN NAN

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