Presentation is loading. Please wait.

Presentation is loading. Please wait.

BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5.

Similar presentations


Presentation on theme: "BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5."— Presentation transcript:

1 BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7

2 ASSIGNMENT Review Quiz # 2 Start reading Chapter 5

3 History Boolean Logic 1854 - George Boole describes his system for symbolic and logical reasoning: An Investigation into the Laws of thought Boolean logic later becomes the basis for computer design

4 Quote “No matter how correct a mathematical theorem may appear to be, one ought never to be satisfied that there was not something imperfect about it until it also gives the impression of being beautiful.” George Boole - Quoted in D MacHale, Comic Sections (Dublin 1993)

5 Basic Idea Boolean Logic is two valued logic – True – False

6 JAVA The strings “true” and “false” are keywords in JAVA – Constants representing boolean value Variables can be declared to as boolean boolean b1, b2 ; Variables can be assigned a value b1 = true ; b2 = false ;

7 Relational Operators < // less than <= // less than or equal to > // greater than >= // greater than or equal to == // equal to != // not equal to

8 Examples ( 4 < 5) ( 4 <= 3) ( 3 > 3) ( 3 >= 3) (7 == 2) ( 2 != 7)

9 Example values ( 4 < 5) ( 4 <= 3) ( 3 > 3) ( 3 >= 3) (7 == 2) ( 2 != 7) true false true false true

10 Example assignments boolean b1, b2, b3, b4, b5, b6; b1 = ( 4 < 5); b2 = ( 4 <= 3); b3 = ( 3 > 3); b4 = ( 3 >= 3); b5 = (7 == 2); b6 = ( 2 != 7);

11 Can be more complex boolean b1, b2; b1 = ( 4 < (3 + 2)); int x = 7; b2 = ((x – 5) <= 3);

12 “AND” OPERATION ABA && B False TrueFalse TrueFalse True

13 Using AND boolean b1 ; double inc = 73000.0; int numChild = 5; 11 = ((inc 3));

14 “OR” OPERATION ABA || B False True FalseTrue

15 Using or boolean b2 ; double inc = 73000.0; int numChild = 5; b2 = ((inc 3));

16 “NOT” OPERATION A!A FALSETRUE FALSE

17 Using not boolean b3 ; double inc = 73000.0; int numChild = 5; b3 = !(!(inc 3));

18 Multiple modes of expression We can express booleans in many ways – Table – Formula – Symbolic diagram

19 The mathematical basis for computer design An open switch can represent – Zero – False A closed switch can represent – One – True A switch can control another switch – A logic gate

20 Boolean Arithmetic -True → False -False → True False + False → False False + True → True True + False → True True + True → True False * False → False False * True → False True * False → False True * True → True

21 Boolean Arithmetic -(0) → 1 //looks funny -(1) → 0 // more like -1,1 0 + 0 → 0 0 + 1 → 1 1 + 0 → 1 1 + 1 → 1 (no “carry”) 0 * 0 → 0 0 * 1 → 0 1 * 0 → 0 1 * 1 → 1 (intuitive)

22 Boolean Arithmetic -(0) → 1 // NOT -(1) → 0 0 + 0 → 0 0 + 1 → 1 1 + 0 → 1 1 + 1 → 1 OR 0 * 0 → 0 0 * 1 → 0 1 * 0 → 0 1 * 1 → 1 AND

23 Notation To keep things straight Boolean negation “!” replaces “-” Boolean addition “ || “ replaces “+” Boolean multiplication “&&” replaces “*”

24 Boolean Operations & Circuits AND OR NOT X

25 Boolean Expressions & Circuits AND: z = x && y ; OR: z = x || y ; NOT: z = !x ; X x y z x y z z x

26 Some practice Express the “circuit” as – A truth table – A formula (boolean assignment in JAVA)

27 So what? We can represent numbers in binary We can perform operations on boolean So, we can use boolean circuits to automate arithmetic operations

28 Binary Addition 0 + 0 = 00 0 + 1 = 01 1 + 0 = 01 1 + 1 = 10 A + B = CS

29 Addition 0 + 0 = 00 0 + 1 = 01 1 + 0 = 01 1 + 1 = 10 A + B = CS ABCS 0000 0101 1001 1100

30 QUESTION: “Carry in” 0 + 0 + 0 = ?? 0 + 0 + 1 = ?? 0 + 1 + 0 = ?? 0 + 1 + 1 = ?? 1 + 0 + 0 = ?? 1 + 0 + 1 = ?? 1 + 1 + 0 = ?? 1 + 1 + 1 = ??

31 QUESTION: “Carry in” 0 + 0 + 0 = 00 0 + 0 + 1 = 01 0 + 1 + 0 = 01 0 + 1 + 1 = 10 1 + 0 + 0 = 01 1 + 0 + 1 = 10 1 + 1 + 0 = 10 1 + 1 + 1 = 11


Download ppt "BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5."

Similar presentations


Ads by Google