Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Techniques :: Logic & Truth Tables

Similar presentations


Presentation on theme: "Programming Techniques :: Logic & Truth Tables"— Presentation transcript:

1 Programming Techniques :: Logic & Truth Tables
Last modified: 6th July 2019

2 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. ?

3 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) …

4 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…

5 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 ? ?

6 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 ? ? ? ?

7 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 ? ? ? ?

8 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 ? ? ? ? ? ? ? ?

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

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

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

12 𝑎∧𝑏  𝒂 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 𝑥 𝑥 𝑦

13 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...

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

15 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!

16 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?

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

18 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 𝑎 𝑐 ? 𝑃 𝑏 𝑏 𝑐

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


Download ppt "Programming Techniques :: Logic & Truth Tables"

Similar presentations


Ads by Google