Logical Operators

Logical operators are used in programing and circuitry to transform inputs. Logical operators always deal with true and false: 1 or 0. Thus they always operate on the binary representation of a number or value. In circuitry this is usually a HIGH or LOW voltage.

There are two types of logical operators:

  • Normal logical operators which operate on singular true false values.
  • And bitwise logical operators which operate on sets of bits representing values.

The symbols shown below are common (and correct for C based languages), however not globally true.

OperatorBitwise SymbolLogical Symbol
AND&&&
OR||
NOT!
XORN/A

See: Bitwise Operators for more detailed information about the bitwise versions of these operations.

AND Operator

The AND operator returns true only if both operands are true. Otherwise, it returns false.

Operand 1Operand 2Result
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse

OR Operator

The OR operator returns true if at least one operand is true. Otherwise, it returns false.

Operand 1Operand 2Result
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse

NOT Operator

This flips the bits of the input. true becomes false, and false becomes true.

OperandResult
truefalse
falsetrue

XOR Operator

The XOR operator, also known as the exclusive OR operator, returns true if only one operand is true, but not both. Otherwise, it returns false.

Operand 1Operand 2Result
truetruefalse
truefalsetrue
falsetruetrue
falsefalsefalse