Download presentation
Presentation is loading. Please wait.
1
CPS120 Introduction to Computer Science
Boolean Logic
2
Decision Making In Computers
A circuit quite simply allows one out of two choices to be made depending on its inputs When decisions are made in a computer program, they are simply the result of a computation in which the final result is either TRUE or FALSE The value zero (0) is considered to be FALSE. Any positive or negative value is considered to be TRUE (usually represented by 1)
3
Using Logical Operators
When complex decisions must be coded into an algorithm, it may be necessary to "chain together" a few relational expressions (that use relational operators) This is done with logical operators (also called Boolean operators.) && is the logical AND operator || is the logical OR operator ! is the logical NOT operator
4
Boolean Logic The term Boolean or simply BOOL is named for a 19th century mathematician named George Boole. Boole is recognized for applying concepts of algebra to human logic. Boole moved concepts of human thought process away from the metaphysical or abstract logic of Aristotle to more tangible mathematical principles.
5
I Know This Concept If you have ever taken a True or False test, you have used Boolean logic. In the Boolean system an object can exist in only one of two states, there is no third choice This is a central concept in programming.
6
What are the different Boolean Operators?
Depending on code being used the operators come with different names and use. Some languages support more Boolean Operators, some less. There are some basic standard operators. The result of any Boolean operation should be a TRUE or FALSE
7
AND Two or more items must agree (be evaluated to the same result) for the expression to be true. 1 AND 1 would evaluate to TRUE 0 AND 1 would evaluate to FALSE 1 AND 0 would evaluate to FALSE 0 AND 0 would evaluate to FALSE 1 AND 1 AND 1 would evaluate to TRUE 1 AND 1 AND 0 would evaluate to FALSE
8
OR One, both or more items must agree. If both inputs are FALSE, the result it FALSE. 1 OR 1 would evaluate to TRUE 0 OR 1 would evaluate to TRUE 0 OR 0 would evaluate to FALSE
9
NOT Reverses the input. If TRUE is input, the result id FALSE; if FALSE is input, the result is TRUE. 1 would evaluate to FALSE 0 would evaluate to TRUE
10
XOR (eXclusive OR) Only one input may be TRUE, if both are TRUE the entire result id FALSE. 1 XOR 1 would evaluate to FALSE 1 XOR 0 would evaluate to TRUE 0 XOR 1 would evaluate to TRUE 0 XOR 0 would evaluate to FALSE
11
NAND (Not AND) This basically negates AND:
1 NAND 1 would evaluate to FALSE 1 NAND 0 would evaluate to TRUE 0 NAND 0 would evaluate to TRUE 0 NAND 1 would evaluate to TRUE
12
Truth Tables Use this truth table to determine the results of the logical operators. In this table, 1 represents TRUE and 0 represents FALSE. Note that the ! symbol (the logical NOT operator) changes a TRUE to a FALSE. AND OR NOT A B A && B A || B !A 1 1 1 1 1 1 1 1 1
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.