Logical AND is a logical operation which has the following truth table:
- False AND False = False
- False AND True = False
- True AND False = False
- True AND True = True
More generally:
- AND is true only when all of its arguments are true
- AND is false if any of its arguments are false.
This applies for any number of arguments to AND.
Stated another way (for C and C++ programmers, AND = &&)
- non-zero && non-zero = true
- zero && anything = false
Of course, in C, && is not LogicalAnd but rather ShortCircuitAnd (the second argument is not evaluated unless the first argument is True).
Logical AND is not to be confused with the BitwiseAnd operator. BitwiseAnd operations are often used as a bit mask to clear certain bits without affecting others. For example, 00001111 AND 10101010 results in 00001010. (This was confusing when used in Commodore BASIC, because non-programmers think "and" means "plus": POKE 1,PEEK(1) AND 251 would clear bit 2, not add four.)
For those of us who need to use ThreeValuedLogic, Logical and has the following additional truth values:
- False and Unknown = False
- True and Unknown = Unknown
- Unknown and Unknown = Unknown