2.1 Logical Operators

Logical operators are used in programming. The most common operators are:
 

  • NOT

  • AND

  • OR

  • XOR

A truth table displays all possible outcomes of a logical operator. The input and output values in a truth table must be a Boolean value - usually 0 or 1 but occasionally True or False.

Because calculations can use dozens of logical operators, they are simplified in Boolean Algebra using symbols rather than words.

 

NOT

The NOT logical operator will produce an output which is the opposite of the input.

It is the only logical operator that has a single input.

Truth Table

Boolean Algebra Notation

 NOT A                   A

written as

 

AND

The AND logical operator will output 1 only if both inputs are also 1.

Truth Table

Boolean Algebra Notation

 A AND B               A.B

written as

 

OR

The OR logical operator will output 1 if either input is 1.

Truth Table

Boolean Algebra Notation

 A OR B               A+B

written as

 

XOR

The XOR logical operator will output 1 if the inputs are different and output 0 if the inputs are the same.

Truth Table

Boolean Algebra Notation

 A XOR B              A      B

written as

Multiple Operations

Exam questions will ask you complete truth tables that use more than one logical operator. In the example to the right, you must work out the NOT B column first and then use your answers in that column for the final column.

 

Read the column titles carefully to understand what is expected of you. The AND in the last column is not AND between A and B, it is AND between the NOT B column and the A column.

Questo's Corner

Truth Tables:  Draw and complete the truth tables below.

 

© CSNewbs 2020