Presentation is loading. Please wait.

Presentation is loading. Please wait.

Boolean Logic & Truth Tables In today’s lesson we will look at: a reminder about truth values and NOT, AND, OR and EOR truth tables operator precedence.

Similar presentations


Presentation on theme: "Boolean Logic & Truth Tables In today’s lesson we will look at: a reminder about truth values and NOT, AND, OR and EOR truth tables operator precedence."— Presentation transcript:

1 Boolean Logic & Truth Tables In today’s lesson we will look at: a reminder about truth values and NOT, AND, OR and EOR truth tables operator precedence equivalent expressions

2 Truth Values When we first looked at Boolean Logic, we introduced the idea of truth values – things that we could all agree on as being true or false. In computing, we are usually concerned with truths about circuits, e.g. the switch is on the light is on or mathematical truths (especially is application programming).

3 Mathematical Truths We have looked at Boolean variables, and also used if to test the truth of mathematical comparisons. Mathematical truths are usually easier to determine: –1 is equal to 1 –2 is more than 5 –3 is NOT equal to 5 They might involve a variable, e.g. if x = 10: –x is equal to 1 –x is more than 5 –x is NOT equal to 5 TRUE FALSE TRUE FALSE TRUE

4 Truth Values Truth values are pairs of opposites, and are usually written in one of three ways: –On or Off –True or False –1 or 0 For the rest of this topic we are going to use 0 and 1 as they are easier to write. Most programming languages also allow you to use numbers as Boolean values, with 0 as False and non-zero as True (and Python even allows you to use strings, where “” is False and a non-blank string is True), e.g. if x: is the same as if x > 0: (or if x: is the same as if x != “”:)

5 Truth Table - NOT We can use truth tables to describe the output of a particular Boolean logic operation. Truth tables describe the output for all possible inputs e.g. the NOT operator toggles the truth value to its opposite value: pNOT p 01 10 NOT operates on a single value, so there are only two possible inputs; 0 or 1 Inputs and outputs are labelled

6 Truth Table - OR The OR operator gives a true result if any of the input values is true, e.g. pqp OR q 000 011 101 111 OR operates on two values, so there are four possible inputs

7 Truth Table - AND The AND operator gives a true result if both of the input values are true, e.g. pqp AND q 000 010 100 111

8 Truth Table - EOR The EOR operator gives a true result if the two input values are different, e.g. pqp EOR q 000 011 101 110

9 Is Anything Always True? The following always give the same results: p OR NOT p is always 1 p AND NOT p is always 0 pNOT pP AND NOT p 010 100 pNOT pP OR NOT p 011 101

10 Combining Operators AND and OR can work with more than two inputs, just take a pair of inputs at a time: Just like BIDMAS for arithmetic, there is a correct order to combinations of AND and OR. pqRp OR q OR r 0000 0011 0101 0111 1001 1011 1101 1111

11 Operator Precedence There are rules about which operations should be done first; this is known as operator precedence: –operations inside brackets are done first –AND is done before OR In fact, sometimes a AND b is written as a.b and a OR b can be written as a+b – this can help you to remember the order, as multiplication comes before addition in BIDMAS for ordinary arithmetic.

12 Duality Look at the truth tables for AND and OR – what do you see? If you swap 0 for 1 you get the other table! This is a property known as duality, and it can be useful for simplifying calculations (or logic circuits) pqp OR q 111 101 011 000 pqp AND q 000 010 100 111

13 DeMorgan’s Duals This property leads to two rules, called DeMorgan’s Duals: –NOT(a OR b) = NOT a AND NOT b –NOT(a AND b) = NOT a OR NOT b It’s unlikely that you will need to know these for GCSE Computing, but they can be useful for simplifying calculations or logic circuits. We will look at logic circuits and the symbols used in them in the next lesson.


Download ppt "Boolean Logic & Truth Tables In today’s lesson we will look at: a reminder about truth values and NOT, AND, OR and EOR truth tables operator precedence."

Similar presentations


Ads by Google