Truth Tables and Logic Diagrams Jackie Dawes School of Computing Teesside University Which bit is this? This session is designed to support the development of lesson plans for the Binary Logic, Truth Tables and Logic Diagrams part of the GCSE curricula: Explain why data is represented in computer systems in binary form Understand and produce simple logic diagrams using the operations NOT, AND and OR Produce a truth table from a given logic diagram Explain why data is represented in computer systems in binary form Binary • Every computer processor is made of millions of tiny switches that can be turned off or on, i.e. they only have two states • Computers need a number system that only has two digits: the binary number system • The two binary digits (0 and 1) are called bits and correspond to the off/on positions of the switches in the computer processor Binary and logic • Logic in computing is very simple, it either is or it isn’t • There are three common ways to represent logic in computing: – Logic Circuit diagrams – Truth Tables – Boolean expression • Computer circuits use bits – 0 means a 0V voltage input – 1 means a 5V or a 3.3V voltage input • Logic gates and logic diagrams use bits – 0 means false – 1 means true Understand and produce simple logic diagrams using the operations AND, NOT, and OR Logic Gates and Truth Tables • Logic gates are very basic components in any computer – e.g. the CPU is constructed from logic gates • The gates we are looking at today are AND, OR and NOT • They take one or more inputs and produce an output • A single gate can be as simple as on/off switch, on = true, off = false • Gates can be used together to show the outcome when a combination of events happen Logic Gates and Truth Tables continued… • A truth table is a table of 1s and 0s arranged to show the results (outputs) from all possible inputs. Eg Inputs A Output B C Z 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1 GCSE Logic Gates http://www.docstoc.com/docs/21954668/Elementary-Logic-Gates Inverter (NOT Gate) • this gate will invert the input • It has one input • This is the symbol used for a NOT gate • So, Z = A Truth Table for an Inverter A Output 0 1 1 0 AND Gate • It has at least two inputs • Its output will only be 1 when all the inputs are 1, otherwise the output will be 0 • This is the symbol for an AND gate • So, Z = A.B (a dot is used to show the AND operation) Truth table for an AND gate A B Z 0 0 0 0 1 0 1 0 0 1 1 1 OR Gate • It has at least two inputs • Its output will be 1 when any of the inputs are 1 • This is the symbol for an OR gate • So Z = A+B ( a plus is used to show the OR operation) Truth Table for an OR Gate A B Z 0 0 0 0 1 1 1 0 1 1 1 1 http://logic.ly/demo/ Playing with Gates Produce a truth table from a given logic diagram Logic Diagrams • Logic diagrams use a symbolic description of logic gates • The gates are combined to represent a particular logic expression, e.g. Creating truth tables from logic diagrams • Process: – Select each combination of inputs one at a time – Replace their inputs with their respective values – Follow the output through the diagram until the output is reached – List the final output for each state in the truth table next to the value of each input – Easier to do than to say, so…… • Do the Exercise (separate hand-out) Boolean Values and Operators • We can produce truth tables from a variety of sources, e.g. to represent these situations we could write: Boolean value – if the burglar alarm rings then call the police Boolean value – if the alarm clock goes off and it’s a week day then get up Boolean value else go back to sleep Boolean operator Based on slides produced by Jay Chapman and Tyrone Davison, Teesside University Truth Tables programming language syntax Action if the burglar alarm rings then Boolean value call the police Based on slides produced by Jay Chapman and Tyrone Davison, Teesside University Truth Tables Boolean value Boolean value if the alarm clock rings and it’s a week day then Action on True Boolean operator get up else Action on False go back to sleep Based on slides produced by Jay Chapman and Tyrone Davison, Teesside University Questions? Jackie Dawes School of Computing Teesside University