New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski
Boolean Boolean - EASY Can have one of two values ▫true or false ▫on or off ▫1 or 0 Boolean Expressions Evaluate to be true or false Boolean Operators Operators that are used with Booleans Boolean Math/Algebra or Boolean Logic Uses Booleans and Boolean operators Used in computers
Boolean Expressions A simple use of Boolean concept Expressions that evaluate to True or False They use comparison operators (=,, =) Compare two sides – numbers, variables, expressions Ask a specific question – Is the expression TRUE or FALSE ? You have used them in math before = ? Addition = 37 ? Boolean true = 40 ? Boolean false
Boolean Expressions (continued) Expression (Comparison Operator) Question Asked L=RThe left equals the right, True or False? 3 + 5= equals 8, True or False? TRUE L<RThe left is less than the right, True or False? 16/4<316/4 is less than 3, True or False? FALSE L>RThe left is greater than the right, True or False? 50*100>50050*100 is greater than 500, True or False? TRUE
Boolean Operators Three basic ones: AND, OR, NOT Most other operators are based on these Compares Boolean values or expressions or change them Evaluates to a Boolean (True or False, On or Off, 1 or 0) Rules for each operator are different Boolean Value Or Expression (True or False) Boolean Operator Boolean Value Or Expression (True or False) Boolean Value (True or False)
Boolean Logic Also know as Boolean Algebra or Boolean Math What is it? ▫Only two values. ▫The Math of comparing and manipulating Booleans So what? ▫Most important principle of modern computers. Developed in the 1850s by George Boole ▫A founder of computer science
Boolean Logic Expression: A AND B For A AND B to be true BOTH A AND B must be true (Both Sides Must Be True) AND Truth Table: Boolean Logic (continued) AND A Boolean Expression Boolean Operator B Boolean Expression Evaluates to TRUEANDTRUE ANDFALSE ANDTRUEFALSE ANDFALSE
Boolean Logic Lets look at an example: Marbles
Boolean Logic Lets look at an example: Marbles Blue? = false Red? = true Marble? = true Blue? = false Red? = true Marble? = true
Boolean Logic We can group the marbles: Is there a set of Marble? = true Marble? = true
Boolean Logic Blue? = true Red? = true We can also group the marbles: The marble is Blue? = true ? The marble is Red? = true ?
Boolean Logic Blue? = true Red? = true Is there a set: (Marble? = true) AND (Blue? = true) is true Is there a set: (Blue? = true) AND (Red? = true) is true?
Blue? = true Red? = true Boolean Logic Find the set with (Blue? = true) AND (Red? = true) Find the set with (Blue? = true) AND (Green? = true) Find the set with (Purple? = true) AND (Green? = true)
For A OR B to be true EITHER A OR B can be true (Only One Side Needs to be True) OR Truth Table: Boolean Logic (continued) OR A Boolean Expression Boolean Operator B Boolean Expression Evaluates to TRUEORTRUE ORFALSETRUE FALSEORTRUE FALSEORFALSE
Blue? = true Red? = true Find the set with (Blue? = true) OR (Red? = true) Boolean Logic (continued)
Find the set with (Blue? = true) OR (Red? = true) Find the set with (Blue? = true) OR (Green? = true) Find the set with (Purple? = true) OR (Green? = true) Boolean Logic (continued)
NOT Boolean Operator Boolean Expression Evaluates to NOTTRUEFALSE NOTFALSETRUE NOT is really easy – it just gives you the opposite value
Blue? = true Red? = true Find the set with (NOT Blue? = true) Find the set with (NOT Red? = true) Find the set with (NOT Purple? = true) Boolean Logic (continued)
Find the set with (NOT Red? = true) Find the set with (NOT Blue? = true) Find the set with (NOT Purple? = true) Boolean Logic (continued)
Order of Operation 1.Parenthesis 2.NOT 3.AND 4.OR Examples: NOT true AND true false AND true FALSE NOT ( false AND true ) NOT false TRUE true OR false AND true true OR false TRUE ( true OR false ) AND true true AND true TRUE Boolean Logic (continued)
Booleans in Computer Science Search Engines (Average User) ▫Use Boolean Logic to limit: AND, OR, NOT ▫Boolean Order of Operations holds Conditionals (Programmer) ▫Boolean Expressions and Boolean Logic ▫Used in Conditionals
Booleans in Computer Science Digital Gates (Boolean Gates) in Chips/Circuits (Hardware Engineer) ▫Fundamental building block of a computer ▫Uses Booleans True and False 1’s and 0’s ▫Boolean Logic To figure out if gate is open/closed
Summary Booleans can have only two values Boolean expressions Use comparison operators (=, ) Evaluate to TRUE or FALSE Boolean Operators Three Basic Operators: AND, OR, NOT Compare Boolean values/expressions or change them Evaluate to TRUE or FALSE Boolean Logic Use Boolean Operators: AND, OR, NOT The math of comparing and manipulating Booleans. Order of Operation: ( ), NOT, AND, OR