Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

Unit 10

Boolean Logic
Boolean logic
Unit 10 Advanced programming and databases

Binary logic – AND gate


• If both inputs are 1 (True) then the output is 1 (True)
• Otherwise the output is 0 (False)

A B P
INPUT
A 0 0 0
OUTPUT
P 0 1 0
INPUT
B 1 0 0

Logic statement: P = A AND B 1 1 1

Logic Diagram Truth Table


Boolean logic
Unit 10 Advanced programming and databases

Binary logic – OR gate


• If either input is 1 (True) then the output is 1 (True)
• Otherwise the output is 0 (False)

A B P
INPUT
A 0 0 0
OUTPUT
P 0 1 1
INPUT
B 1 0 1

Logic statement: P = A OR B 1 1 1

Logic Diagram Truth Table


Boolean logic
Unit 10 Advanced programming and databases

Binary logic – NOT gate


• If 0 is input it outputs 1 (True)
• If 1 is input it outputs 0 (False)

A P
INPUT OUTPUT
0 1
A P
1 0

Logic statement: P = NOT A

Logic Diagram Truth Table


Boolean logic
Unit 10 Advanced programming and databases

NAND, NOR and XOR gates


• A NAND gate gives the opposite results to an
AND gate
• It is the same as combining an AND gate with a NOT gate
• In the same way, a NOR gate is the same as combining an OR gate with a NOT gate

• An Exclusive OR gate (XOR) will only be true if one of the inputs is true
• It will be false if both inputs are true, hence it’s exclusive

• Complete the truth tables for NAND, NOR and


XOR gates
• Also, guess what the symbol would be for each
Boolean logic
Unit 10 Advanced programming and databases

NAND, NOR and XOR gates

A B A NAND B A NOR B A XOR B


0 0 1 1 0
0 1 1 0 1
1 0 1 0 1
1 1 0 0 0
Boolean logic
Unit 10 Advanced programming and databases

Combining two logic gates


• We can combine logic gates together to make more
complex circuits

INPUT
A R OUTPUT
P
INPUT
B

A B R = A AND B P = NOT R
0 0
Logic statement:
0 1
P= NOT R
1 0 P=NOT ( A AND B)
1 1
Boolean logic
Unit 10 Advanced programming and databases

Logic Expression for the circuit

Q= C OR D
Q= ( A AND B) OR ( NOT B)

A B C = A AND B D = NOT B Q = C OR D

0 0
0 1
1 0
1 1
Boolean logic
Unit 10 Advanced programming and databases

Truth Table for logic circuits with two inputs


Boolean logic
Unit 10 Advanced programming and databases

Construct Truth table with 3 inputs

A B C D=A AND B E=B OR C X= D OR E

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
Logic statement
X = D OR E 1 0 1
X= ( A AND B) OR ( B OR C) 1 1 0
1 1 1
Boolean logic
Unit 10 Advanced programming and databases
Boolean logic
Unit 10 Advanced programming and databases

Modelling real life – security lighting

What would the circuit diagram for this situation


look like?
The security light must
come on if it senses
movement AND it is night time,
OR if someone presses a
manual override switch
Boolean logic
Unit 10 Advanced programming and databases

Modelling real life


Sensor detects Night time Manual override Security
movement = TRUE = TRUE Button = TRUE Light On

AND OR =

Sensor detects
Movement (S)

Night time (N) Security


Light
Manual override
Button (B)
Boolean logic
Unit 10 Advanced programming and databases

The truth table


Sensor detects OUTPUT
Movement (S) R

Night time (N) Security


Light (P)
Manual override
Button (B)

S N B R = S AND N P = R OR B
0 0 0 0 0
0 0 1 0 1
0 1 0 0 0 Logic statement:
0 1 1 0 1 P= R OR B
P = (S AND N) OR B
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 1
Boolean logic
Unit 10 Advanced programming and databases

Problem Statement
Boolean logic
Unit 10 Advanced programming and databases

Draw logic circuit for the logic expression


Boolean logic
Unit 10 Advanced programming and databases

X = 1 if ((A is NOT 1 OR B is 1) NOR C is 1) NAND ((A is 1 AND C is 1) NOR B is 1)

X = (( NOT A OR B) NOR C) NAND (( A AND C) NOR B)


Boolean logic
Unit 10 Advanced programming and databases

Truth Table
Boolean logic
Unit 10 Advanced programming and databases

X = 1 if (( A is 1 AND B is 1 ) OR ( B is 1 AND C is NOT 1 ))

X = (( A AND B ) OR ( B AND NOT C))


Boolean logic
Unit 10 Advanced programming and databases

Truth table for the logic statement


Boolean logic
Unit 10 Advanced programming and databases

Logic Gate from Truth table

Not A and B ( is the logic statement for the above truth table )
Steps to how to write the logic statement and draw the logic circuit from the truth table
1. First identify the rows where outcome is 1, in the above truth table only 2 nd row outcome/x is 1
2. The write the expression for this Row. In second ROW , A off and B is on and when A is off and B is on
the output is one so Boolean expression is NOT A AND B
3. After this draw the logic circuit for this statement
Boolean logic
Unit 10 Advanced programming and databases

Write the logic statement and draw logic gate


for the truth table

(NOT X AND NOT Y) OR ( X and NOT Y)


1. For each row in the truth table where outcome is 1, write the logic statements and then join them with OR
in between
2. First row outcome is 1 , logic statement for the first row is NOT X and NOT Y
3. Third row outcome is 1, logic statement for the third row is X and NOT Y
4. Join the statement for these rows with OR
5. (NOT X AND NOT Y) OR ( X and NOT Y)
Boolean logic
Unit 10 Advanced programming and databases

Logic statement for the truth table

You might also like