boolean logic csc 171 fall 2004 lecture 7. assignment review quiz # 2 start reading chapter 5

31
BOOLEAN LOGIC BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7

Post on 21-Dec-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

““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

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

““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

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

““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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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