Download presentation
1
Computer Programming Boolean Logic
3
What is Boolean Logic? Boolean logic is a system for determining the truth of a statement (or expression) based on whether certain variables are true or false. For example: In the statement, “I will go for a walk if it is sunny,” the decision is based on whether it is true that it is ‘sunny.’ 3 Trade & Industrial Education
4
Historical Note George Boole ( ) was an English mathematician who devised a system of symbols and equations to represent logical decisions. Boolean Algebra was not widely used until the invention of computers. Boolean logic expressions are used to design electronic circuits and to represent decision-making in software. 4 Trade & Industrial Education
5
Use of Boolean Logic A combination of conditions, variables, and operators are used to determine if an expression is True or False. It can also be used to determine which elements can be members of a given set. Trade & Industrial Education
6
How are these categories different?
Brown-eyed AND Male Brown-eyed OR Male Trade & Industrial Education
7
Who would be in these groups?
NOT male AND wearing jeans NOT <16 Trade & Industrial Education
8
Like Mathematics, Boolean logic has operators
Mathematic Operators + - x / = Trade & Industrial Education
9
Boolean Operators && ( AND ) || ( OR ) ! ( NOT )
Cheese || Pepperoni && !Anchovies Trade & Industrial Education
10
Boolean logic has an order of operations
Mathematic Order of Operations is PEMDAS - Parentheses first Exponents next Multiplication and Division Addition and Subtraction. Trade & Industrial Education
11
Order of Boolean Operations
Parentheses are not operators, but indicate grouping, consider these first. NOT (!) must be considered next. AND ( && ) is considered next. OR ( || ) is considered last. Trade & Industrial Education
12
!Tall && Blonde || Rich Consider the NOT first. !Tall is short.
Consider the AND next. !Tall and Blonde, in other words, Short and Blonde. Consider the OR next. This person can be either Short and Blonde, or they can be Rich. They can also be Short, Blonde, and Rich. Trade & Industrial Education
13
Order of Operations Parentheses first, then NOT (!) , then && , then || !Tall && Blonde || Rich !(Tall && Blonde) || Rich !Tall && !Blonde || Rich Trade & Industrial Education
14
Venn Diagrams Venn Diagrams can be used to visualize Boolean expressions. Trade & Industrial Education
15
Venn Diagram A B A && B Trade & Industrial Education
16
Where is !A A B Trade & Industrial Education
17
Where is A || B ? A B Trade & Industrial Education
18
Truth Tables Truth tables are used to evaluate possible combinations of variables and operators. Trade & Industrial Education
19
A || B (A OR B) A B A || B True False Trade & Industrial Education
20
A && B (A AND B) A B A && B True False Trade & Industrial Education
21
!A (NOT A) A !A True False Trade & Industrial Education
22
!A || B (NOT A OR B) A B !A || B True False
Trade & Industrial Education
23
Check for Understanding
Determining the results of a Boolean expression is known as evaluating it. All Boolean expressions evaluate to either True or False. Trade & Industrial Education
24
Evaluate: What would be printed, A or B?
boolean blonde = false; if ( blonde) System.out.println(“A”); if ( !blonde) System.out.println(“B”); Trade & Industrial Education
25
Evaluate: What would be printed, A or B?
boolean tall = false; boolean male = true; if ( male && tall) System.out.println(“A”); if ( male || tall) System.out.println(“B”); Trade & Industrial Education
26
Evaluate: What would be printed, A or B?
boolean x = false; boolean y = true; if ( x && y) System.out.println(“A”); if ( !x && y) System.out.println(“B”); Trade & Industrial Education
27
Shade in A || !B A B Trade & Industrial Education
28
Shade in A && !B A B Trade & Industrial Education
29
Shade in !A && !B A B Trade & Industrial Education
30
Will it print? boolean x = true; boolean y = false; if ( x && !y)
System.out.print(“A”); Trade & Industrial Education
31
Will it print? boolean x = true; boolean y = false; if (! x || y)
System.out.print(“A”); Trade & Industrial Education
32
With what you know… Can you evaluate a boolean expression?
Trade & Industrial Education
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.