> lang > and | ![]() |
| Documentation |
|
Result = Expression AND Expression
Depending on the expression, the AND operation can be either a logical AND or a numerical AND. In case of two boolean expressions, a logical AND operation is performed. In case of two integer numbers, a numerical AND operation is performed.
The logical AND operator takes two boolean expressions and returns a true or false value. The results returned by this operator is shown in the following table:
| A | B | A AND B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| TRUE | FALSE | FALSE |
| TRUE | TRUE | TRUE |
The numerical AND operator takes two integer values and returns an integer value. Each corresponding bit of the specified values are combined according to the following table:
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The numerical AND operator can be used to test the bit pattern of a number. It can also be used to mask out selected bits of a number. The following table gives some examples of how the AND operator works on two integer numbers.
| Expression | Explanation |
|---|---|
| 10 AND 20 = 0 |
10 = binary 01010
20 = binary 10100 Hence 10 AND 20 = 0
|
| 10 AND -20 = 8 |
10 = binary 00000000000000000000000000001010
-20 = binary 11111111111111111111111111101100 Hence 10 AND -20 = 8 (binary 1000)
|
| 20 AND -20 = 4 |
20 = binary 00000000000000000000000000010100
-20 = binary 11111111111111111111111111101100 Hence 20 AND -20 = 4 (binary 100)
|