What are logic gates and truth tables?

153 views

This is a topic I’ve been struggling with and I need help understanding what different logic gates do and how to make truth tables for each.

In: 2

7 Answers

Anonymous 0 Comments

Some good comments here. I’d like to add that what’s so great about logic gates, is that they sit at a crossover point between electricity and math. Boolean math can be used to perform any other math, and electricity can be used to perform boolean math incredibly fast.

You may enjoy (or tear your hear out at) the web-based nandgame.com, where you start by constructing logic gates, then use them as building blocks for more and more complex functions, and in the end put together a rudimentary computer.

Anonymous 0 Comments

If you’re an electrical engineer or a physics person, wires are messy and complicated. You can measure a wire’s potential (volts), current (amps), or resistance (ohms), and these can be any number: You might measure 1 volt or 2 volts or 10 volts or 4.7125 volts. Wires store charge (capacitance) and create magnetic fields (inductance).

Computer people don’t like thinking about all that complicated stuff. Instead, computer people think about a simple imaginary cartoon world where wires can only be “on” or “off”. Sometimes “on” is called “1” or “true”. Sometimes “off” is called “0” or “false”.

A logic gate is simply a “box” that has some input wires (usually 2 inputs) and output wires (usually 1 output).

A truth table is a “specification” or “manual” for a logic gate. To make a truth table, first, you put each possible combination of 0’s and 1’s somebody might put on the input wires into a row in the truth table. For example:

– If you have a logic gate with one input wire labeled A, there will be 2 rows in the truth table, corresponding to {A=0}, {A=1}.
– If you have a logic gate with two input wires labeled A,B, there will be 4 rows in the truth table, corresponding to {A=0,B=0}, {A=0,B=1}, {A=1,B=0}, {A=1,B=1}.
– If you have a logic gate with three input wires labeled A, B, C, there will be 8 rows in the truth table, corresponding to {A=0,B=0,C=0}, {A=0,B=0,C=1}, {A=0,B=1,C=0}, {A=0,B=1,C=1}, {A=1,B=0,C=0}, {A=1,B=0,C=1}, {A=1,B=1,C=0}, {A=1,B=1,C=1}.

There are four common, important logic gates: AND, OR, XOR, NOT [1] [2]. You just have to memorize these names, the corresponding truth tables, and the corresponding circuit diagram symbols.

Logic gates are mostly useful as building blocks for more complicated circuits. There are many, many resources about this. See [this Sebastian Lague video](https://www.youtube.com/watch?v=QZwneRb-zqA) for an example of building an addition circuit from logic gates.

[1] Some textbooks / courses might say there are six. The other two are called NAND, NOR.

[2] NOT has 1 input wire and 1 output wire. All the others have 2 input wires and 1 output wire.

Anonymous 0 Comments

Here’s the boolean operations that you represent with single logic gates.

AND has two inputs, and outputs true only if both inputs are true. On diagrams, these gates look like a half circle on the output side and a square on the input side.

OR has two inputs, and outputs true only if either input is true. On diagrams, these gates look like curves bowing outward and meeting at a point on the output side, and bowing inward on the input side.

XOR has two inputs, and outputs true only if the two inputs are different. It looks like an OR gate, but with an extra curve on the input side.

NOT gates have only one input, and output the opposite of the input. Alone, it looks like a triangle pointing to the output, with a little circle on the point.

Sometimes the little circle symbol is combined with the other three gates to make NAND, NOR, XNOR gates. It’s the same as those first ones, but the output is the opposite. So a NAND outputs false only when both inputs are true.

You can also use the triangle part of the not gate without the little circle. It’s just a passthrough, so for logic purposes, it doesn’t really matter.

To draw a truth table, make a table such that there’s a column for every input and output, and a row for every combination of inputs. Then fill in the output column with the output that’s produced by the input listed in that row.

For these logic gates, they’ll be pretty small. Two rows for the NOT gate, and four for the others. You can combine logic gates in your design to implement more complicated logic though, and if you have more inputs, you’ll need a bigger table.

Anonymous 0 Comments

Not an explanation, but potentially helpful for independent learning:

I am not an EE, but basic classical (true/false) logic is the same regardless of discipline. If you are still struggling with logic gates, it may help to learn them in a different way. In mathematics, logic is often taught fully in the abstract, so if you think that intuitive language-based examples will help you understand better, then you might consider looking at a philosophical logic textbook. Philosophy students learn basic classical logic “sententially,” meaning that the logical statements are treated as though they roughly approximate English language sentences. Students begin with problem sets that ask them to “translate” sentences into logical propositions, and learn the fundamental operators that way. Worth noting is that logic is usually taught to mathematics and linguistics students using set theory. You will not learn set theory in an introductory philosophical logic textbook, so keep that in mind if it applies to your situation.

Classical Logic and its Rabbit Holes by Nelson Lande is an excellent and accessible book that will teach you sentential logic. Unlike many other logic textbooks, it is inexpensive and it focuses specifically on fluency in sentential logic for about the first half, before introducing first-order logic and the axioms via synthesis (however, do EEs use first-order logic?). You could also look up philosophical logic tutorials on YouTube.

As I mentioned, the book was written for philosophy undergraduates, so it does not use the same symbols or terminology as electrical engineering, but it is fundamentally the same. You may also think about taking a logic class in your university’s philosophy department. You may find that you enjoy philosophy too! Good luck with your studies!

Anonymous 0 Comments

When you do “traditional” math, you have operations such as addition, subtraction, multiplication, etc. This math works using the numbers we know.

Logic gates are a different kind of math (Boolean algebra). Instead of using every number, you only use 1 and 0, which can be interpreted as True and False. This type of math uses other type of operations, mainly AND, OR and NOT (and derivations of them).

Truth tables are like multiplication tables, in the sense of “this numbers combined using this operation give this result”. You can interpret them from everyday speech, for instance, when you say “this is not true” is like saying “this is false”. Thus, the NOT gate is an operation when a 1 becomes a 0 and vice versa.

Anonymous 0 Comments

A logic gate represents boolean logical operators. Those operators take one or more boolean inputs (either a 1/TRUE or a 0/FALSE) and evaluate them to generate an output. A Truth Table is just all possible inputs and outputs.

For example, you have the AND operator. It returns 1/TRUE if both inputs are TRUE. If the inputs are 1 and 1 then it gives you 1. If the inputs are 0 and 0 then it gives you 0. If the inputs are 1 and 0 then it gives you 0, because the inputs are not matched.

So the table would look like this:

Input1 Input 2 = Output

0 AND 0 = 0

1 AND 0 = 0

0 AND 1 = 0

1 AND 1 = 1

The most useless useful logic gate is “YES” which is a straight pass through. 1 outputs 1, 0 outputs 0. “Not” is also pretty helpful, it inverts the input. 1 -> 0 and 0 -> 1.

Then you have AND where if the two inputs are matched it outputs 1 and OR where if *any* input is 1 it outputs 1.

It gets a little more complicated with XOR, named “exclusive OR.” XOR requires exactly one input to be 1 in order to output 1. 1 OR 1 = 1 while 1 XOR 1 = 0.

Then there’s the “not” operators, which are just a combination of NOT and another operator, but they’re useful enough that they get their own names.

NAND is “NOT AND” so anything that gives you a TRUE with AND will give you a FALSE instead and vice versa. 1 NAND 1 = 0 while 0 NAND 0 = 1 and 0 NAND 1 also = 1.

Take the output of the operator and put it through a NOT gate and that’s the N version of the operator. NAND, NOR, XNOR

Anonymous 0 Comments

A logic gate, in electrical engineering, takes some number of inputs binary inputs and produces a binary output. The binary inputs are basically just TRUE or FALSE, but you also might see them represented as 1 or 0, or ON and OFF.

I’ll walk through an OR gate because that’s a simple one. An OR gate has two inputs and produces one output. If any of the inputs are true, the output will be true, and the output will be false if both inputs are false. To give a real world example, let’s say you were designing a toll road. You want to let the drivers through if they have either paid the toll or have a pass, so you can take an OR gate and one of the inputs is “has pass” and the other is “paid toll” and you can use the output of that to decide to open the gate.

A truth table is just a list of all the inputs and what output you’d get. For an OR gate, it would look like this

False, False: False

False, True: True

True, False: True

True, True: True