New Mexico Computer Science For All Booleans and
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 (=, <, >, <= or >=) �Compare two sides – numbers, variables, expressions �Ask a specific question – Is the expression TRUE or FALSE ? • You have used them in math before. 24 + 13 = ? 24 + 13 = 37 ? 24 + 13 = 40 ? Addition 37 Boolean true Boolean false
Boolean Expressions (continued) Expression (Comparison Operator) Question Asked L = R The left equals the right, True or False? 3+5 = 8 3 + 5 equals 8, True or False? TRUE L < R The left is less than the right, True or False? 16/4 < 3 16/4 is less than 3, True or False? L > R The left is greater than the right, True or False? 50*100 > 500 FALSE 50*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 1850 s by George Boole ▫ A founder of computer science
Boolean Logic (continued) • 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: AND A Boolean Expression Boolean Operator B Boolean Expression Evaluates to TRUE AND TRUE AND FALSE AND TRUE FALSE AND FALSE
Boolean Logic Lets look at an example: Marbles
Boolean Logic Lets look at an example: Marbles Blue? = false Red? = true Marble? = true
Boolean Logic We can group the marbles: • Is there a set of Marble? = true
Boolean Logic We can also group the marbles: • The marble is Blue? = true ? • The marble is Red? = true ? Blue? = true Red? = true
Boolean Logic 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) Blue? = true Red? = true
Boolean Logic (continued) • For A OR B to be true EITHER A OR B can be true (Only One Side Needs to be True) • OR Truth Table: OR A Boolean Expression Boolean Operator B Boolean Expression Evaluates to TRUE OR TRUE OR FALSE TRUE FALSE OR FALSE
Boolean Logic (continued) Find the set with (Blue? = true) OR (Red? = true) Blue? = true 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) Blue? = true Red? = true
Boolean Logic (continued) NOT is really easy – it just gives you the opposite value NOT Boolean Operator Boolean Expression Evaluates to NOT TRUE FALSE NOT FALSE TRUE
Boolean Logic (continued) Find the set with (NOT Blue? = true) Find the set with (NOT Red? = true) Find the set with (NOT Purple? = true) Blue? = true Red? = 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) Blue? = true Red
Boolean Logic (continued) • Order of Operation 1. 2. 3. 4. Parenthesis NOT AND OR • Examples: NOT true AND true false AND true FALSE NOT ( false AND true ) NOT false TRUE true OR false AND true OR false TRUE ( true OR false ) AND true TRUE
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
- Slides: 23