Programming Techniques Logic Truth Tables jamiedrfrostmaths com www
Programming Techniques : : Logic & Truth Tables jamie@drfrostmaths. com www. drfrostmaths. com @Dr. Frost. Maths Last modified: 6 th July 2019
www. drfrostmaths. com Registering on the Dr. Frost. Maths 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. Everything is completely free. Why not register? With Computer Science questions by: Your code on any mini-tasks will be preserved. Note: The Tiffin/DFM Computer Science course uses Java. Script as its core language. Most code examples are therefore in Java. Script. 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: true && false true && true false && false true || false !true !false true && !true ? false true? false ? true? false ? Logic Operators in Programming Reminder: && and || or ! not We’d typically combine Boolean values in code within conditions for if and while constructions, e. g. if(x > 5 && x < 10) …
Logic Gates 1 Digital circuits consist of components (e. g. ‘gates’) with connecting channels (the lines). Two different voltage levels (often 0 V and 5 V) are used to represent the two binary values: 0 and 1, representing false and true respectively. 0 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. 0 1 1 0 ? ?
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. 0 0 1 1 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. 0 0 1 1 1 0 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. 0 0 1 1 1 0 0 1 1 0 ? ? 0 1 0 0 ? ?
Test Your Understanding So Far Remember to have a column for each individual wire. 0 0 0 1 0 1 0 0 ? 1 1 1 0
Three Inputs ? ? 0 0 0 0 1 0 0 1 1 ? 1 0 0 1 1 1 1 1 0 1 1 1 ? 0 ?
Test Your Understanding ? ? 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 1 ?
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: ? ? ? ? a ? b
My 3 rd 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 3 rd Year University Project I used red for 0 and green for 1. The wires could also optionally have multi-bit values.
My 3 rd 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 Q 3 ? AND ? NOT 1 1 ? 1 0 ? b
Review 1 What component is this? 2 OR/disjunction ? ? Draw a logic table for the following circuit. 3 4 Draw a logic table for the following circuit: 0 0 1 0 0 0 0 1 0 1 0 1 1 ? 0 1 0 0 0 1 1 0 ? 1 0 0 0 1 1 1 1 0 1 1 1
Coding Mini-Tasks Return to the Dr. Frost. Maths site to complete the various tasks on logic circuits.
- Slides: 19