Programming Techniques :: Logic & Truth Tables

Slides:



Advertisements
Similar presentations
Programming Logic Gate Functions in PLCs
Advertisements

Chapter 4 Gates and Circuits.
Lecture 3. Boolean Algebra, Logic Gates Prof. Sin-Min Lee Department of Computer Science 2x.
Logic and data representation Revision. AND gate A B A B All inputs have to be true ( i.e 1) for the output of the gate to be high, in all other cases.
Computer Science 1000 Digital Circuits. Digital Information computers store and process information using binary as we’ve seen, binary affords us similar.
Module 3.  Binary logic consists of :  logic variables  designated by alphabet letters, e.g. A, B, C… x, y, z, etc.  have ONLY 2 possible values:
Chapter 3.5 Logic Circuits. How does Boolean algebra relate to computer circuits? Data is stored and manipulated in a computer as a binary number. Individual.
1 Boolean Algebra & Logic Gates. 2 Objectives Understand the relationship between Boolean logic and digital computer circuits. Learn how to design simple.
Boolean Algebra and Computer Logic Mathematical Structures for Computer Science Chapter 7.1 – 7.2 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Boolean.
LOGIC GATES.
Teaching Computing to GCSE Level with Python Session 3.
1 Registers A register is a group of n flip-flops each of them capable of storing one bit of information There are two types of registers: parallel and.
GCSE Computing – Topic 2 Lesson 5a – Binary Logic CHALLENGE TO: identify the different types of logic diagrams. ASPIRE TO: Construct a truth table for.
LOGIC GATES. INTRODUCTION TO LOGIC GATES Boolean functions may be practically implemented by using electronic gates. The following points are important.
Week 1: Introduction and Logic gates IT3002 – Computer Architecture
Logic gates.
Sequential Logic An Overview
EGR 2131 Unit 4 Combinational Circuits: Analysis & Design
Unit 1 Logical operators.
GCSE OCR Computing A451 Binary logic Computing hardware 6.
Activity 1 5 minutes Grab a whiteboard and pen, come to the front and work out the Truth Table for the following circuit: R A B C Q.
Basics of Logic gates - Part 1
Combinational circuits
Truth Table to Statement Form
Dr.Ahmed Bayoumi Dr.Shady Elmashad
Component 1 Logical operators.
Prof. Sin-Min Lee Department of Computer Science
Logic Gates.
Computer Science 210 Computer Organization
CSIS-110 Introduction to Computer Science
Chapter 2.3 Binary Logic.
Fundamentals & Ethics of Information Systems IS 201
Chapter 4 Gates and Circuits.
Teaching Computing to GCSE
Agenda – 2/12/18 Questions? Readings: CSI 4, P
3.4 Computer systems Boolean logic Lesson 2.
For OCR GCSE Computing Unit 1 - Theory
Computer Science 210 Computer Organization
Fundamentals of Computer Systems
Computers in the real world Objectives
A-level Computer Science
Logic Gates.
Unit 10 Arithmetic-logic Units
GCSE Computer Science – Logic Gates & Boolean Expressions
Latches The second part of CS231 focuses on sequential circuits, where we add memory to the hardware that we’ve already seen. Our schedule will be very.
Binary Logic.
XOR Function Logic Symbol  Description  Truth Table 
Truth tables Mrs. Palmer.
CPSC 121: Models of Computation
Copyright © Cengage Learning. All rights reserved.
Outline Registers Counters 5/11/2019.
Digital Circuits and Logic
EGR 2131 Unit 12 Synchronous Sequential Circuits
CPSC 121: Models of Computation
ECE 352 Digital System Fundamentals
Programming Techniques :: Records
Programming Techniques :: File Handling
Programming Techniques :: String Manipulation
Programming Techniques :: Flow Diagrams and Pseudocode
Data Representation :: Binary & Hexadecimal
Running & Testing :: IDEs
Digital Electronics and Logic Design
Programming Techniques :: Data Types and Variables
Networks :: Wireless Networks
Programming Techniques :: Sorting Algorithms
Running & Testing Programs :: Translators
Data Representation :: Compression
Programming Techniques :: Arithmetic & Boolean Operators
Programming Techniques :: Computational Thinking
Presentation transcript:

Programming Techniques :: Logic & Truth Tables jamie@drfrostmaths.com www.drfrostmaths.com @DrFrostMaths Last modified: 6th July 2019

www.drfrostmaths.com ? Everything is completely free. Why not register? Registering on the DrFrostMaths platform allows you to save all the code and progress in the various Computer Science mini-tasks. It also gives you access to the maths platform allowing you to practise GCSE and A Level questions from Edexcel, OCR and AQA. With Computer Science questions by: Your code on any mini-tasks will be preserved. Note: The Tiffin/DFM Computer Science course uses JavaScript as its core language. Most code examples are therefore in JavaScript. Using these slides: Green question boxes can be clicked while in Presentation mode to reveal. Slides are intentionally designed to double up as revision notes for students, while being optimised for classroom usage. The Mini-Tasks on the DFM platform are purposely ordered to correspond to these slides, giving your flexibility over your lesson structure. ?

Recap of Boolean operators We have seen that values need not be numeric: they could be Boolean values, i.e. ‘true’ or ‘false’ (corresponding to 1 and 0). We have already seen that we can combine Boolean values using appropriate operators: Logic Operators in Programming Reminder: && and || or ! not true && false  false true && true  true false && false  false true || false  true false || false  false !true  false !false  true true && !true  false ? ? ? ? ? ? ? ? We’d typically combine Boolean values in code within conditions for if and while constructions, e.g. if(x > 5 && x < 10) …

Logic Gates Digital circuits consist of components (e.g. ‘gates’) with connecting channels (the lines). Two different voltage levels (often 0V and 5V) are used to represent the two binary values: 0 and 1, representing false and true respectively. 1 1 1 1 1 Gates in circuits take one or two binary inputs and output a single binary value. How these inputs are combined depends on the type of gate. Let’s look at each individually first…

NOT gate A NOT gate has the same affect as a NOT/!/¬ in programming languages. “Not true” is false and “not false” is true. A truth table is a way of stating what the output would be for all input values of a logical expression. We have to consider all input values; if we have a single input 𝑎, this input could be 0 or 1. 𝒂 𝑵𝑶𝑻 𝒂 1 ? ?

AND gate An AND gate similarly has the same affect as AND/&& in programming languages. Both inputs have to be 1/true for the output to be 1/true. This time we have two inputs (say 𝑎 and 𝑏). We have to consider all combinations of inputs. In general, if you have 𝑛 inputs, then you will need 2 𝑛 rows in your table. 𝒂 𝒃 𝒂 𝐀𝐍𝐃 𝒃 1 ? ? ? ?

OR gate An OR gate similarly has the same affect as OR/|| in programming languages. If either (or both) inputs are 1, the output is 1. 𝒂 𝒃 𝒂 𝐎𝐑 𝒃 1 ? ? ? ?

Combining gates We can combine gates together to represent more complicated Boolean expressions. 𝑎 𝑏 Fro Tip: Have a column in your table for each individual wire to break the problem down. 𝒂 𝒃 𝐍𝐎𝐓 𝒂 𝐍𝐎𝐓 𝒂 𝑨𝑵𝑫 𝒃 1 ? ? ? ? ? ? ? ?

Test Your Understanding So Far 𝑎 𝑏 Remember to have a column for each individual wire. ? 𝒂 𝒃 𝒂 𝐎𝐑 𝒃 𝐍𝐎𝐓 (𝒂 𝐎𝐑 𝒃) 1

Three Inputs ? ? ? ? ? 𝒂 𝒃 𝒄 𝒂 𝐎𝐑 𝒃 𝒂 𝐎𝐑 𝒃 𝐀𝐍𝐃 𝒄 1 𝑎 𝑏 𝑐 𝒂 𝒃 𝒄 𝒂 𝐎𝐑 𝒃 𝒂 𝐎𝐑 𝒃 𝐀𝐍𝐃 𝒄 1 ? ? ? ? ? There are 3 inputs so we need 2 3 =8 rows.

Test Your Understanding 𝑎 𝑏 𝑐 𝒂 𝒃 𝒄 𝒃 𝐀𝐍𝐃 𝒄 𝒂 𝐎𝐑 (𝒃 𝐀𝐍𝐃 𝒄) 1 ? ? ? ?

𝑎∧𝑏  𝒂 AND 𝒃 𝑎∨𝑏  𝒂 OR 𝒃 ¬𝑎  NOT 𝒂 Mathematical Notation for Logical Operators In Programming we know we use operators like &&, || and ! to represent conjunction (and), disjunction (or) and negation (not) respectively. But in Mathematics we have formal notation when dealing with Boolean values: Fun Fact: The ∧ symbol itself is known as a ‘wedge’. 𝑎∧𝑏  𝒂 AND 𝒃 𝑎∨𝑏  𝒂 OR 𝒃 ¬𝑎  NOT 𝒂 ? ? ? Draw a logic diagram representing: (a) ¬𝑥 (b) 𝑥∨¬𝑦 ? a ? b 𝑥 𝑥 𝑦

My 3rd Year University Project In my third year of university I wrote some software that allowed you to design logic circuits… Clicking this button would then graphically show the circuit in operation. (See next slide!) You could set the inputs by clicking on these dots...

My 3rd Year University Project I used red for 0 and green for 1. The wires could also optionally have multi-bit values.

My 3rd Year University Project There were a large number of different types of circuit components you could add to the diagram. An ALU for example is an Arithmetic Logic Unit, allowing arithmetic operations such as addition, if each input consisted of multiple bits rather than a single 0/1 value. There were enough types of components to build (and test) an entire CPU architecture!

Binary Counter using my software (Note: None of this is in the GCSE syllabus) This is a 3-bit binary counter, i.e. it counts up in binary starting from 000. The vertical outputs are the 3 outputs bits (although with the bits reversed, so 000, 100, 010, 110, …) This is known as a “T Flip Flop”. Every fixed amount of time all flip flops simultaneously receive a ‘pulse’ (from something called the ‘clock’), which causes each to output each time. If the input is 1, the output is the reverse of what it previously outputted. If the input is 0, it outputs what it previously outputted. Can you verify that this circuit works?

Exam Question OCR May 2018 Q3 ? AND NOT ? ? 1 1 1 ? b

Review ? ? ? ? What component is this? 1 Draw a logic diagram for the following expression: ¬𝒂∨ 𝒃∧𝒄 2 ? OR/disjunction ? 𝑎 𝑏 𝑐 Draw a logic table for the following circuit. 𝒂 𝒃 𝒄 𝑷 1 3 Draw a logic table for the following circuit: 4 ? 𝑎 𝒂 𝒃 𝒄 1 𝑎 𝑐 ? 𝑃 𝑏 𝑏 𝑐

Coding Mini-Tasks Return to the DrFrostMaths site to complete the various tasks on logic circuits.