Download - BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5
![Page 1: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/1.jpg)
BOOLEAN LOGICBOOLEAN LOGIC
CSC 171 FALL 2004
LECTURE 7
![Page 2: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/2.jpg)
ASSIGNMENTASSIGNMENT
Review Quiz # 2
Start reading Chapter 5
![Page 3: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/3.jpg)
HistoryHistoryBoolean LogicBoolean 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
![Page 4: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/4.jpg)
QuoteQuote
“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)
![Page 5: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/5.jpg)
Basic IdeaBasic Idea
Boolean Logic is two valued logic– True– False
![Page 6: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/6.jpg)
JAVAJAVA
The strings “true” and “false” are keywords in JAVA– Constants representing boolean value
Variables can be declared to as booleanboolean b1, b2 ;
Variables can be assigned a valueb1 = true ;b2 = false ;
![Page 7: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/7.jpg)
Relational OperatorsRelational Operators< // less than<= // less than or equal to> // greater than>= // greater than or equal
to == // equal to!= // not equal to
![Page 8: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/8.jpg)
ExamplesExamples( 4 < 5) ( 4 <= 3) ( 3 > 3)( 3 >= 3) (7 == 2)( 2 != 7)
![Page 9: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/9.jpg)
Example valuesExample values( 4 < 5)
( 4 <= 3) ( 3 > 3)( 3 >= 3) (7 == 2)( 2 != 7)
truefalsefalsetruefalsetrue
![Page 10: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/10.jpg)
Example assignmentsExample assignmentsboolean b1, b2, b3, b4, b5, b6;b1 = ( 4 < 5); b2 = ( 4 <= 3); b3 = ( 3 > 3);b4 = ( 3 >= 3); b5 = (7 == 2);b6 = ( 2 != 7);
![Page 11: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/11.jpg)
Can be more complexCan be more complexboolean b1, b2;b1 = ( 4 < (3 + 2));int x = 7; b2 = ((x – 5) <= 3);
![Page 12: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/12.jpg)
““AND” OPERATIONAND” OPERATION
A B A && B
False False False
False True False
True False False
True True True
![Page 13: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/13.jpg)
Using ANDUsing ANDboolean b1 ;double inc = 73000.0;int numChild = 5;11 = ((inc < 50000.0) && (numChild >
3));
![Page 14: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/14.jpg)
““OR” OPERATIONOR” OPERATION
A B A || B
False False False
False True True
True False True
True True True
![Page 15: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/15.jpg)
Using orUsing orboolean b2 ;double inc = 73000.0;int numChild = 5;b2 = ((inc < 50000.0) || (numChild >
3));
![Page 16: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/16.jpg)
““NOT” OPERATIONNOT” OPERATION
A !A
FALSE TRUE
TRUE FALSE
![Page 17: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/17.jpg)
Using notUsing notboolean b3 ;double inc = 73000.0;int numChild = 5;b3 = !(!(inc < 50000.0) && !(numChild >
3));
![Page 18: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/18.jpg)
Multiple modes of expressionMultiple modes of expression
We can express booleans in many ways– Table– Formula– Symbolic diagram
![Page 19: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/19.jpg)
The mathematical basis for The mathematical basis for computer designcomputer design
An open switch can represent– Zero– False
A closed switch can represent– One– True
A switch can control another switch– A logic gate
![Page 20: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/20.jpg)
Boolean ArithmeticBoolean 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
![Page 21: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/21.jpg)
Boolean ArithmeticBoolean 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)
![Page 22: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/22.jpg)
Boolean ArithmeticBoolean 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
![Page 23: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/23.jpg)
NotationNotation
To keep things straight
Boolean negation “!” replaces “-”Boolean addition “ || “ replaces “+”Boolean multiplication “&&” replaces “*”
![Page 24: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/24.jpg)
Boolean Operations & CircuitsBoolean Operations & Circuits
AND
OR
NOT
X
![Page 25: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/25.jpg)
Boolean Expressions & CircuitsBoolean Expressions & Circuits
AND: z = x && y ;
OR: z = x || y ;
NOT: z = !x ;
X
xy z
xy z
zx
![Page 26: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/26.jpg)
Some practiceSome practice
Express the “circuit” as– A truth table– A formula (boolean assignment in JAVA)
![Page 27: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/27.jpg)
So what?So what?
We can represent numbers in binaryWe can perform operations on booleanSo, we can use boolean circuits to automate
arithmetic operations
![Page 28: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/28.jpg)
Binary AdditionBinary Addition
0 + 0 = 00
0 + 1 = 01
1 + 0 = 01
1 + 1 = 10
A + B = CS
![Page 29: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/29.jpg)
AdditionAddition
0 + 0 = 00
0 + 1 = 01
1 + 0 = 01
1 + 1 = 10
A + B = CS
A B C S
0 0 0 0
0 1 0 1
1 0 0 1
1 1 0 0
![Page 30: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/30.jpg)
QUESTION: “Carry in”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 = ??
![Page 31: BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649d635503460f94a4581c/html5/thumbnails/31.jpg)
QUESTION: “Carry in”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