emb1006 boolean logic jonathan-lee jones. overview what is logic types of logic gate truth tables...

Post on 15-Jan-2016

220 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

EMB1006 Boolean Logic

Jonathan-LeeJones

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

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.

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.

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

Types of Logic Gate

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

Types of Logic Gate

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

Types of Logic Gate

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

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:

Truth Tables

A B O

0 0

0 1

1 0

1 1

AND Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1

1 0

1 1

AND Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1 0

1 0

1 1

AND Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1 0

1 0 0

1 1

AND Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1 0

1 0 0

1 1 1

AND Gate

A

B

O

Truth Tables

A B O

0 0

0 1

1 0

1 1

OR Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1

1 0

1 1

OR Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1 1

1 0

1 1

OR Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1 1

1 0 1

1 1

OR Gate

A

B

O

Truth Tables

A B O

0 0 0

0 1 1

1 0 1

1 1 1

OR Gate

A

B

O

Truth Tables

A O

0

1

NOT Gate

AO

Truth Tables

A O

0 1

1

NOT Gate

AO

Truth Tables

A O

0 1

1 0

NOT Gate

AO

Examples

A

OB

C

D E

A B C D E O

Examples

A

OB

C

D E

A B C D E O

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

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

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

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

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

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

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

Examples

A

OB

C

DE

A B C D E O

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

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

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

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

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

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

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

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

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.

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.

Binary Arithmetic

A B RESULT CARRY

Binary Arithmetic

A B RESULT CARRY

0 0

0 1

1 0

1 1

Binary Arithmetic

A B RESULT CARRY

0 0 0

0 1 1

1 0 1

1 1 0

Binary Arithmetic

A B RESULT CARRY

0 0 0 0

0 1 1 0

1 0 1 0

1 1 0 1

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.

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:

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.

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.

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?

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.

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.

Boolean Algebra

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

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

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)

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)".

top related