Presentation is loading. Please wait.

Presentation is loading. Please wait.

Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba <= b.

Similar presentations


Presentation on theme: "Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba <= b."— Presentation transcript:

1

2 Boolean Algebra

3 Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba <= b

4 Negating Boolean Assertions Rewriting code for easier readability is usually why we negate Boolean assertions if(!(x < 5)) becomes if( x > = 5)

5 Boolean Algebra Operands(values):true, false Operators:and (&&) or( | |) not(!)

6 DeMorgan’s Laws not(A or B) = not A and not B !(A || B) = !A && !B not(A and B) = not A or not B !(A && B) = !A || ! B

7 Application of DeMorgan’s Law “Craps” If you roll a 7 or 11 on the first roll, you win If you roll a 2, 3, or 12 on the first roll, you lose Otherwise on subsequent rolls you want to roll your original number before you roll a 7 to win

8 Here is the truth table that proves the first DeMorgan’s Law. not(A or B) = not A and not B !(A || B) = !A && !B AB !(A||B)!A!B!A&&!B true false truefalse truefalse truefalsetruefalse true True

9 Following is the truth table that proves the second DeMorgan's Law. not(A and B) = not A or not B !(A && B) = !A || ! B AB !(A&&B)!A!B!A||!B true false truefalsetruefalsetrue falsetrue falsetrue false true Notice that columns with the titles ! (A && B) and ! A || ! B result in the same answers.

10 initial roll – compare subsequent rolls until you won or lost the game: do –while with the sentinel: while( !((sum == point) || (sum == 7)) ); while( (sum != point) && (sum != 7) );

11 Proving Demorgan’s Law I ABnot(A or B)not Anot Bnot A and not B 110000 100010 010100 001111

12 Proving Demorgan’s Law II ABnot(A and B)not Anot Bnot A or not B 11 10 01 00


Download ppt "Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba <= b."

Similar presentations


Ads by Google