Logic operations.

Slides:



Advertisements
Similar presentations
Digital Circuits. Review – Getting the truth table The first step in designing a digital circuit usually is to get the truth table. That is, for every.
Advertisements

التصميم المنطقي Second Course
Boolean Algebra and Logic Gate
CS 300 – Lecture 3 Intro to Computer Architecture / Assembly Language Digital Design II.
Combinational Comparators
10/22/2004EE 42 fall 2004 lecture 221 Lecture #22 Truth tables and gates This week: Circuits for digital devices.
Lecture 3. Boolean Algebra, Logic Gates
Part 2: DESIGN CIRCUIT. LOGIC CIRCUIT DESIGN x y z F F = x + y’z x y z F Truth Table Boolean Function.
Lecture 3. Boolean Algebra, Logic Gates Prof. Sin-Min Lee Department of Computer Science 2x.
Chapter 4 Gates and Circuits. 4–2 Chapter Goals Identify the basic gates and describe the behavior of each Describe how gates are implemented using transistors.
Lecture 3. Error Detection and Correction, Logic Gates Prof. Sin-Min Lee Department of Computer Science 2x.
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:
CPSC 171 Introduction to Computer Science Boolean Logic, Gates, & Circuits.
Binary Addition CSC 103 September 17, 2007.
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
ADDERS Half Adders Recall that the basic rules of binary addition are as indicated below in Table 2-9. A circuit known as the half-adder carries out these.
1 Boolean Algebra & Logic Gates. 2 Objectives Understand the relationship between Boolean logic and digital computer circuits. Learn how to design simple.
CS1Q Computer Systems Lecture 6 Simon Gay. Lecture 6CS1Q Computer Systems - Simon Gay2 Algebraic Notation Writing AND, OR, NOT etc. is long-winded and.
Digital Systems I EEC 180A Lecture 4 Bevan M. Baas.
EE2420 – Digital Logic Summer II 2013 Hassan Salamy Ingram School of Engineering Texas State University Set 4: Other Gates.
Lecture 9 Topics: –Combinational circuits Basic concepts Examples of typical combinational circuits –Half-adder –Full-adder –Ripple-Carry adder –Decoder.
Islamic University Of Gaza, Nael Aburas Data Storage Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas
4. Computer Maths and Logic 4.2 Boolean Logic Logic Circuits.
Digital Logic. 2 Abstractions in CS (gates) Basic Gate: Inverter IO IO GNDI O Vcc Resister (limits conductivity) Truth Table.
CS1Q Computer Systems Lecture 6 Simon Gay. Lecture 6CS1Q Computer Systems - Simon Gay2 Algebraic Notation Writing AND, OR, NOT etc. is long-winded and.
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
How does a Computer Add ? Logic Gates within chips: AND Gate A B Output OR Gate A B Output A B A B
WORKING PRINCIPLE OF DIGITAL LOGIC
4–1. BSCS 5 th Semester Introduction Logic diagram: a graphical representation of a circuit –Each type of gate is represented by a specific graphical.
LOGIC CIRCUITLOGIC CIRCUIT. Goal To understand how digital a computer can work, at the lowest level. To understand what is possible and the limitations.
L OGIC G ATES Computer Organization – week 3. W HAT ’ S ALU? 1. ALU stands for: Arithmetic Logic Unit 2. ALU is a digital circuit that performs Arithmetic.
Week 1: Introduction and Logic gates IT3002 – Computer Architecture
CPS120 Introduction to Computer Science
Invitation to Computer Science, C++ Version, Fourth Edition
Dr.Ahmed Bayoumi Dr.Shady Elmashad
CSCI-100 Introduction to Computing
Chapter 2.3 Binary Logic.
Introduction to Computer Science - Lecture 6
Combinational Circuits
Digital Signals Digital Signals have two basic states:
Dr. Clincy Professor of CS
Fundamentals & Ethics of Information Systems IS 201
XOR, XNOR, and Binary Adders
Invitation to Computer Science, Java Version, Third Edition
Agenda – 2/12/18 Questions? Readings: CSI 4, P
Dr. Clincy Professor of CS
3.4 Computer systems Boolean logic Lesson 2.
CISC101 Reminders Your group name in onQ is your grader’s name.
XOR, XNOR, & Binary Adders
Week 7: Gates and Circuits: PART II
CS Chapter 3 (3A and ) Part 3 of 8
Digital Logic.
Logic operations.
Logic Gates.
Logic Gates.
CS Chapter 3 (3A and ) – Part 2 of 5
Gates Type AND denoted by X.Y OR denoted by X + Y NOR denoted by X + Y
COMS 361 Computer Organization
GCSE Computer Science – Logic Gates & Boolean Expressions
Digital Logic.
DIGITAL ELECTRONICS B.SC FY
Combinational Circuits
Dr. Clincy Professor of CS
Lecture 5 Binary Operation Boolean Logic. Binary Operations Addition Subtraction Multiplication Division.
XOR Function Logic Symbol  Description  Truth Table 
Digital Circuits and Logic
Digital Circuits.
XOR, XNOR, and Binary Adders
More Example.
Presentation transcript:

Logic operations

Logic operations We have already seen keywords or, and, not used in Python Had a specific purpose – Boolean expressions. For example: if x >= 0 and x < 10: print("x is a single digit") Python has a set of operators for bitwise computations: & : bitwise AND | : bitwise OR ~ : bitwise NOT >>: shift to the right <<: shift to the left

A bit of intuition… 21 << 1 5 | 6 5 & 6 21 >> 1 42 ? ? 10 & bit-wise AND | bit-wise OR ^ bit-wise XOR 21 >> 1 10

A bit of intuition… 21 << 1 5 | 6 5 & 6 ~0 21 >> 1 Sometimes the bits are almost visible: 10101 101 110 101 110 21 << 1 5 & 6 5 | 6 000 10101 & bit-wise and | bit-wise or ^ bit-wise exclusive or ~ bit-wise not NOTE ~0 is -1 because it flips all the bits including sign bit ~000 is 111 21 >> 1 ~0

A bit of intuition… 21 << 1 5 | 6 5 & 6 ~0 21 >> 1 Sometimes the bits are almost visible: 10101 101 110 101 110 21 << 1 5 & 6 5 | 6 101010 100 111 000 10101 & bit-wise and | bit-wise or ^ bit-wise exclusive or ~ bit-wise not NOTE ~0 is -1 because it flips all the bits including sign bit ~000 is 111 21 >> 1 ~0 111 1010

AND OR NOT Truth tables x y AND(x,y) x y OR(x,y) x NOT(x) 1 1 1 1 1 1 input output input output input output x y AND(x,y) x y OR(x,y) x NOT(x) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 AND outputs 1 only if ALL inputs are 1 OR outputs 1 if ANY input is 1 NOT reverses its input Let’s construct truth tables for the operations that we have just described. (They should have it in the handout, so we can just look over the handout) AND OR NOT

All computation x y fn(x,y) 1 1 1 1 1 1 Truth table … consists of functions of bits, or boolean values Boolean inputs x,y,… can only be 0 or 1 (False or True). Boolean functions can output only 0 or 1 (False, True). inputs output x y fn(x,y) 1 1 1 1 1 1 Truth table

Lots of bits! x y z fn(x,y,z) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 output inputs x y z fn(x,y,z) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Truth table

Logic gates and circuits

Reviewing… We have: explored a wide range of data types learned how different encodings are used for different types learned that, at the core of all data stored in the computer are bits observed different operations that can be performed on these bits (AND, OR, NOT) We have one BIG QUESTION remaining… HOW IS COMPUTATION ACTUALLY CARRIED OUT?

In a computer, each bit is represented as a voltage (1 is +5v and 0 is 0v) Computation is simply the deliberate combination of those voltages! Feynman: Computation is just a physics experiment that always works! 101010 42 110011 ADDER circuit 51 Fenyman – awesome physicist, amazing work in quantum mechanics, Nobel prize in 1965 9 001001

In a computer, each bit is represented as a voltage (1 is +5v and 0 is 0v) Computation is simply the deliberate combination of those voltages! Feynman: Computation is just a physics experiment that always works! 101010 42 (1) set input voltages 000000 ADDER circuit 9 001001

In a computer, each bit is represented as a voltage (1 is +5v and 0 is 0v) Computation is simply the deliberate combination of those voltages! 101010 42 (1) set input voltages 110011 ADDER circuit 51 (2) read output voltages 9 001001

In a computer, each bit is represented as a voltage (1 is +5v and 0 is 0v) Computation is simply the deliberate combination of those voltages! HOW? The focus for this week: Learn to design circuits that can accomplish simple computations! 101010 42 110011 ADDER circuit 51 (2) read output voltages 9 001001

of these boolean functions… We need only three building circuits to compute anything at all input output input output x y AND(x,y) x y OR(x,y) input output x NOT(x) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 input input x x y x y These are standard symbols for the gates. Reviewing our basic knowledge of these boolean functions… x + y x xy output "x or y" output "not x" "x and y"

Circuits from logic gates... ? What are all of the inputs that make this circuit output 1?

Logisim HW 5 – Use Logisim (a free circuit simulation package) to design circuits to perform simple computations Hard? Well, let's recall our claim – we only need AND, OR and NOT to compute anything at all…

Constructive Proof ! xy + xy Formula ! For each input row whose output needs to be 1, build an AND circuit that outputs 1 only for that specific input! Specify a truth table defining any function you want i ii input output x y fn(x,y) iii 1 1 OR them all together 1 1 1 1 Formula ! Minterm Expansion Principle – algorithm for building expressions from truth tables xy + xy minterm

Minterm expansion readily converts into logic gates…

Constructive Proof ! xy + xy x y fn(x,y) 1 1 1 1 1 1 For each input row whose output needs to be 1, build an AND circuit that outputs 1 only for that specific input! Specify a truth table defining any function you want i ii input output x y fn(x,y) iii OR them all together 1 1 1 1 xy + xy 1 1 NOT AND Does this work for the red row? x y Does this work for any other rows?

Constructive Proof ! xy + xy x y fn(x,y) 1 1 1 1 1 1 For each input row whose output needs to be 1, build an AND circuit that outputs 1 only for that specific input! Specify a truth table defining any function you want i ii input output x y fn(x,y) iii OR them all together 1 1 xy + xy 1 1 1 1 How did we handle the rows outputting zero? NOT AND OR NOT AND x y

Constructive Proof ! For each input row whose output needs to be 1, build an AND circuit that outputs 1 only for that specific input! Specify a truth table defining any function you want i ii input output x y fn(x,y) This is a constructive proof that AND, OR, and NOT suffice to build any (boolean) function! iii 1 1 OR them all together 1 1 1 1 How did we handle the rows outputting zero? NOT AND OR NOT AND x y

But... ALL functions are just boolean functions: binary! Constructive Proof ! For each input row whose output needs to be 1, build an AND circuit that outputs 1 only for that specific input! Specify a truth table defining any function you want i ii But... ALL functions are just boolean functions: binary! input output x y fn(x,y) This is a constructive proof that AND, OR, and NOT suffice to build any (boolean) function! iii 1 1 OR them all together 1 1 1 1 How did we handle the rows outputting zero? NOT AND OR NOT AND x y

Example

Try it! the less than or equal circuit (<=) Truth Table Formula We usually know what we want to do… We just have to determine how to build it! Truth Table Formula "English" input bits output bit f(x,y) should output 1 when x <= y otherwise, output 0 x y x <= y 1 1 1 1 1,1,0,1 -x-y + -xy + xy = -x + xy BETTER -> recognize that only one case is a 0, and use a NOT Another circuit to do Less than or Equal 1 1 1 Circuit

Try it! xy + xy + xy the less than or equal circuit (<=) We usually know what we want to do… We just have to determine how to build it! Truth Table Formula "English" input bits output bit f(x,y) should output 1 when x <= y otherwise, output 0 xy + xy + xy x y x <= y 1 1 1 1 1,1,0,1 -x-y + -xy + xy = -x + xy BETTER -> recognize that only one case is a 0, and use a NOT Another circuit to do Less than or Equal 1 1 1 Circuit

x <= y