Lecture 22 Logic - F24
Lecture 22 Logic - F24
Logic Gates
ECE 1004
❖ Today’s lecture:
• Binary Math
• Logic gates and truth tables
• Combinational logic
Read through section 7.4 in Hambley
HW6 due Thursday
Exam 2 is October 30th
Wear a costume for quiz credit!
No quiz today
2
Standard method for negative
numbers
2. 2’s complement
• The most common way to represent a signed binary integer
on a computer is using 2’s complement
• The MSB (left-most bit) is still the sign bit!
• Pros
• It’s fast for a computer to use 2’s complement.
• No special hardware is needed to compute basic
math.
• Cons
• Halves the range of positive numbers that can be
represented in n bits compared to unsigned
How to convert a number to 2’s
complement:
• Positive numbers are not changed.
• Negative numbers are converted in the following
way:
• Flip all the bits (called 1’s complement)
• 0s become 1s
• 1s become 0s
• Add 1 to the flipped bits (called 2’s complement)
• Ignore any “carry out” from most significant bit.
• Overflow is a carry that would require more bits to
store than the number of bits available
Example
• In 8 bits, represent the following numbers:
•1
• 0000 0001
The computer system must be told
• -1
what numbers are “negative” so as
• 1111 1111
to not confuse them with positive
• 127 numbers.
• 0111 1111
• -127
• 1000 0001
Subtracting binary numbers.
• We follow the same basic idea as subtracting
decimals.
• In this case, we negate the subtrahend.
• We negate the subtrahend using 2’s complement.
• Then we can add!
8
Logic Gates!
Used for all kinds of tasks in digital systems:
• Multiplexers
• Registers
• ALUs
• Memory, etc.
NOT Operations:
ഥ =0
• AA
ഥ=𝐴
•A
Aside: A memory cell is made of inverters
The advantage of
doing this is that
noise will prevent the
cell from staying in
the unstable region
The AND Gate
• AND is a logical operation that can operate on at
least two inputs.
• It is represented as AB for inputs A, B.
• AB is read “A and B”
• AND is also called logical multiplication.
• The operation of the AND gate can be seen in the
following truth table.
• The symbol for the AND gate is on the next slide as
well.
AND Truth Table
AND Relations:
• AA = A
• A1 = A
• A0 = 0
• AA = 0
• AB = BA
• A(BC) = (AB)C
3 Input AND Gate
The OR Gate
• OR is a logical operation that can operate on at
least two inputs.
• It is represented as A + B for inputs A, B.
• A + B is read “A or B”
• OR is also called logical addition.
• The operation of the OR gate can be seen in the
following truth table.
• The symbol for the OR gate is on the next slide as
well.
The OR Gate
OR Relations:
• (A + B) + C = A + (B + C) = A + B + C
• A(B + C) = AB + AC
• A+0=A
• A+1=1
ഥ=1
• A+A
• A+A=A
3 Input OR Gate
Using Truth Tables
• You can use truth tables to prove a Boolean
Expression
• You list all possible combinations of inputs
• Then, show the combinations
• The next slide shows the example of associative law
for OR
Additional Gates
• NAND, NOR, XOR Gates
• NAND is just an inverted AND gate
• NOR is just an inverted OR gate
• XOR is the exclusive or
• XOR is a two input logic variables
• XOR is only true when either input is true
• A Buffer is a single input and produces an output with
the same value (for providing output current)
• An Equivalence Gate (aka XNOR) is a high value only
when both inputs are the same value (opposite of XOR)
Symbols
Logic gate
summary
Real-world two-input NAND and its model
Two-input NAND Simplified model
• Both transistors
must be on for
output to be
grounded/low
• (= 0)
• If either transistor
is off, then the
output is high
Building logic gates from switches
• We can build logic gates from voltage-controlled
switches
NAND NOR
+V (HIGH) +V (HIGH)
R R
OUT
OUT
A
If either A or A B If either A
B is low or B is high,
B
(switch open), OUT is low.
OUT is high.
Real-world two-input NOR and its model
If any switch is
on, output is
low
(grounded)