58
EMB1006 Boolean Logic Jonathan- Lee Jones

EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Embed Size (px)

Citation preview

Page 1: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

EMB1006 Boolean Logic

Jonathan-LeeJones

Page 2: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Overview

• What is logic• Types of Logic gate• Truth Tables• Examples to work through• Other Gates• Binary Arithmetic• Boolean Logic in Programming• Boolean Algebra• De Morgan’s Laws

Page 3: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

What is Logic

• Computers and logic are inseparable - right?• They are now but at the start things were much

more hazy.• The first computers were conceived as automatic

arithmetic engines and while their creators were aware that logic had something to do with it all, they weren’t 100% clear as to the how or why.

Page 4: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

What is Logic

Boolean logic is very easy to explain and to understand.• You start off with the idea that some statement P is

either true or false, it can’t be anything in between (this called the law of the excluded middle).

• Then you can form other statements, which are true or false, by combining these initial statements together using the fundamental operators And, Or and Not.

Page 5: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Types of Logic Gate

There are THREE types of fundamental Logic gate. These for the basis for Boolean logic. Other gates exist, but these can be made from combining the three fundamental types.• AND gates• OR gates• NOT gates

Page 6: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Types of Logic Gate

AND GatesThese gates give a true (or 1) response if BOTH their inputs are true.

Page 7: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Types of Logic Gate

OR GatesThese gates give a true (or 1) response if EITHER or BOTH their inputs are true.

Page 8: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Types of Logic Gate

NOT GatesThese gates give a true (or 1) response if their input is false. These are known as INVERTERS

Page 9: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

• The rules for combining expressions are usually written down as tables listing all of the possible outcomes. These are called truth tables.

• They usually use either TRUE of FALSE, or 1 and 0 to represent the data.

• The truth tables for the three fundamental operators these are:

Page 10: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0

0 1

1 0

1 1

AND Gate

A

B

O

Page 11: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1

1 0

1 1

AND Gate

A

B

O

Page 12: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1 0

1 0

1 1

AND Gate

A

B

O

Page 13: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1 0

1 0 0

1 1

AND Gate

A

B

O

Page 14: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1 0

1 0 0

1 1 1

AND Gate

A

B

O

Page 15: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0

0 1

1 0

1 1

OR Gate

A

B

O

Page 16: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1

1 0

1 1

OR Gate

A

B

O

Page 17: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1 1

1 0

1 1

OR Gate

A

B

O

Page 18: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1 1

1 0 1

1 1

OR Gate

A

B

O

Page 19: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A B O

0 0 0

0 1 1

1 0 1

1 1 1

OR Gate

A

B

O

Page 20: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A O

0

1

NOT Gate

AO

Page 21: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A O

0 1

1

NOT Gate

AO

Page 22: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Truth Tables

A O

0 1

1 0

NOT Gate

AO

Page 23: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

Page 24: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

Page 25: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

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 26: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

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 27: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 0

1 0 1 0

1 1 0 1

1 1 1 1

Page 28: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

0 0 0 0

0 0 1 0

0 1 0 0

0 1 1 0

1 0 0 0

1 0 1 0

1 1 0 1

1 1 1 1

Page 29: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

0 0 0 0 1

0 0 1 0 1

0 1 0 0 1

0 1 1 0 1

1 0 0 0 1

1 0 1 0 1

1 1 0 1 0

1 1 1 1 0

Page 30: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

0 0 0 0 1

0 0 1 0 1

0 1 0 0 1

0 1 1 0 1

1 0 0 0 1

1 0 1 0 1

1 1 0 1 0

1 1 1 1 0

Page 31: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

D E

A B C D E O

0 0 0 0 1 1

0 0 1 0 1 1

0 1 0 0 1 1

0 1 1 0 1 1

1 0 0 0 1 1

1 0 1 0 1 1

1 1 0 1 0 0

1 1 1 1 0 1

Page 32: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

DE

A B C D E O

Page 33: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

DE

A B C D E O

0 0 0 0 0 1

0 0 1 0 0 1

0 1 0 1 0 1

0 1 1 1 1 0

1 0 0 1 0 1

1 0 1 1 1 0

1 1 0 1 0 1

1 1 1 1 1 0

Page 34: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

DE

A B C D E O

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 35: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

DE

A B C D E O

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 1

1 0 1 1

1 1 0 1

1 1 1 1

Page 36: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

DE

A B C D E O

0 0 0 0 0

0 0 1 0 0

0 1 0 1 0

0 1 1 1 1

1 0 0 1 0

1 0 1 1 1

1 1 0 1 0

1 1 1 1 1

Page 37: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Examples

A

OB

C

DE

A B C D E O

0 0 0 0 0 1

0 0 1 0 0 1

0 1 0 1 0 1

0 1 1 1 1 0

1 0 0 1 0 1

1 0 1 1 1 0

1 1 0 1 0 1

1 1 1 1 1 0

Page 38: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Other Gates

EOR(XOR) GatesThese gates give a true (or 1) response if one of their inputs is TRUE, but not BOTH. They are EXCLUSIVE OR GATES

A B O

0 0 0

0 1 1

1 0 1

1 1 0

A

B

O

Page 39: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Other Gates

NAND GatesThese gates give a true (or 1) response if BOTH their inputs are 0. They are a combination of A NOT and and AND gate.

A B O

0 0 1

0 1 0

1 0 0

1 1 0

A

B

O

Page 40: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Other Gates

NOR GatesThese gates give a true (or 1) response if both their inputs are 0. They are the combination of a NOT and an OR gate.

A B O

0 0 1

0 1 0

1 0 0

1 1 0

A

B

O

Page 41: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

• Boolean logic can be used to implement binary arithmetic.

• Notice that there is no suggestion that binary arithmetic and Boolean logic are the same thing - they aren’t. Binary arithmetic is just an example of a place value system for representing values. That is, we humans work in base 10 and computers find it easier to work in base two because they don’t have ten fingers.

Page 42: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

• However when you do binary arithmetic you follow standard rules that determine how you should combine bits together to produce result bits.

• These rule can be expressed as combinatorial logic - in other words a truth table.

• Buy using a series of gates, it is then possible to carry out some arithmetic procedures.

Page 43: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

A B RESULT CARRY

Page 44: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

A B RESULT CARRY

0 0

0 1

1 0

1 1

Page 45: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

A B RESULT CARRY

0 0 0

0 1 1

1 0 1

1 1 0

Page 46: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

A B RESULT CARRY

0 0 0 0

0 1 1 0

1 0 1 0

1 1 0 1

Page 47: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

• You can see that this is just another truth table and the combinatorial logic needed for it can be produced in the usual way. Actually this is only a half adder - yes this is the real technical term - in that it doesn’t add a carry bit that might have been generated by a previous pair of bits.

Page 48: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Binary Arithmetic

A B C RESULT CARRY

0 0 0 0 0

0 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

The table for a “full adder”, this too is the correct technical term is:

Page 49: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Logic in Programming

• Boolean logic is fundamental to the design of computer hardware even if it isn’t the whole story. The same holds true for programming.

• A program also needs the element of time built into it to make it work and this takes it beyond the bounds of simple Boolean logic.

• However there are times when simple common sense reasoning lets even the best programmer down.

Page 50: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Logic in Programming

• For example, a common task is making a decision using an IF statement:

• IF (A>0 AND A<10) THEN do something• The bracket following the IF is almost pure Boolean logic

and the something only gets done if it works out to be true.

• So far so simple, so simple in fact that many programmers decide that they don’t need to know anything about Boolean logic at all; a serious error.

Page 51: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Logic in Programming

• Consider how you would change this example so that the “something” was done when the condition was false. The simplest way is to write:

• IF NOT(A>0 AND A<10) THEN do something• Instead of using NOT, a programmer wrote the code like

this:-• IF (A<=0 AND A>=10) THEN do something

• Is this correct? If not, how would you write the statement without using a NOT?

Page 52: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Logic in Programming

• IF (A<=0 AND A>=10) THEN do something• This is incorrect. A can never be BOTH less that or equal to 0

AND greater than or equal to 10.

• The correct NOT of the condition is:• IF (A<=0 OR A>10) THEN do something• The switch from AND to OR shocks many experienced

programmers and it is a source of many programming errors.

Page 53: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Algebra

We don’t always draw logic gates for these. In Boolean Algebra we use different symbols to represent the logic.The basic operations of Boolean algebra are as follows.

• AND (conjunction), denoted x∧y (sometimes x AND y or Kxy), satisfies x∧y = 1 if x = y = 1 and x∧y = 0 otherwise.

• OR (disjunction), denoted x∨y (sometimes x OR y or Axy), satisfies x∨y = 0 if x = y = 0 and x∨y = 1 otherwise.

• NOT (negation), denoted ¬x (sometimes NOT x, Nx or !x), satisfies ¬x = 0 if x = 1 and ¬x = 1 if x = 0.

Page 54: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Algebra

Page 55: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Algebra

X Y X or Y Z (X or Y) or Z

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

(X or Y) or Z

Page 56: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Algebra

X Y X or Y Z (X or Y) or Z

0 0 0 0 0

0 0 0 1 1

0 1 1 0 1

0 1 1 1 1

1 0 1 0 1

1 0 1 1 1

1 1 1 0 1

1 1 1 1 1

(X or Y) or Z

Page 57: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

Boolean Algebra

X Y Z Y or Z X or (Y or Z)

0 0 0 0 0

0 0 1 1 1

0 1 0 1 1

0 1 1 1 1

1 0 0 0 1

1 0 1 1 1

1 1 0 1 1

1 1 1 1 1

X or (Y or Z)

Page 58: EMB1006 Boolean Logic Jonathan-Lee Jones. Overview What is logic Types of Logic gate Truth Tables Examples to work through Other Gates Binary Arithmetic

De Morgan’s Laws

• The rules can be expressed in English as:• The negation of a conjunction is the disjunction of the

negations.• The negation of a disjunction is the conjunction of the

negations.

• or informally as:• "not (A and B)" is the same as "(not A) or (not B)"

and also,• "not (A or B)" is the same as "(not A) and (not B)".