1 / 22

Boolean Algebra

Boolean Algebra. 25 March 2014. Boolean Logic. Invented by George Boole Boolean logic is the basis for modern computer logic. What is a Boolean Variable?. A variable (cell) that holds either true or false Can be thought of conceptually as yes or no. Boolean Expressions: Comparisons.

gaius
Download Presentation

Boolean Algebra

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Boolean Algebra 25 March 2014

  2. Boolean Logic • Invented by George Boole • Boolean logic is the basis for modern computer logic.

  3. What is a Boolean Variable? • A variable (cell) that holds either true or false • Can be thought of conceptually as yes or no

  4. Boolean Expressions: Comparisons • Less than (<) • Greater than (>) • Equal to (=) • Less than or equal to (<=) • Greater than or equal to (>=) • Not equal to (!=)

  5. Boolean Operations • In Math, there are operations: plus, minus, times, etc. • In Boolean Algebra, there are operations as well. • Boolean Operations: • AND • OR • NOT

  6. AND • If every boolean being “and-ed” is true, then the AND operator returns true. • true AND true AND true = true • true AND false AND true = false • Did all students pass the course?

  7. OR • If some boolean being “or-ed” is true, then the OR operator returns true • false OR false OR false = false • false OR false OR true = true • Did at least one student pass?

  8. NOT • NOT(one argument) • If p is true, then NOT p is false. • If p is false, then NOT p is true.

  9. NOT • NOT (circles) • blue & white • NOT(diagrams) • yellow & white • NOT(circles OR diagrams) • white • NOT(circles AND diagrams) • yellow, blue, white • Did neither student pass the course?

  10. Properties • Just as in Math, the operations in Boolean Algebra follow certain properties.

  11. Properties you’ve seen before…

  12. De Morgan’s Laws • NOT (P AND Q) = (NOT P) OR (NOT Q) • NOT (P OR Q) = (NOT P) AND (NOT Q)

  13. De Morgan’s Law (1) • The dog is not both quiet and small • Either the dog is not quiet or it is not small • NOT (QUIET AND SMALL) • (NOT QUIET) OR (NOT SMALL) NOT (A AND B) = (NOT A) OR (NOT B)

  14. De Morgan’s Law (2) • The cat is not black or white • The cat is not black and it is not white • NOT (BLACK OR WHITE) • (NOT BLACK) AND (NOT WHITE) NOT (A OR B) = (NOT A) AND (NOT B)

  15. IF … THEN … ELSE • if (MUST BE LOWERCASE) • No else: do nothing if not true • else: one or the other • else if: nested function

  16. Operators Logical Conditional

  17. N-way Decisions • What if I want to decide between more than 2 alternates? • Nested else statements (else if) • switch – case

  18. additional function capabilities

  19. Random Selection Condition is random function var n = Math.random(); • Choose between options

  20. Converting Random to Integer • Often useful to convert that random number to an integer • 0->1 needs to be changed to 0->3 (or any other number • varnInt = n*4; gets the range correct • But only want integer only: Math.floor returns the largest integer less than the value • varnInt = Math.floor(n*4);

  21. Changing Other Attributes • Instead of changing value, can change image

  22. Changing in the function • If you have two things that you want to change in your HTML Can change them in the function • Usually do NOT return value

More Related