Brought to you by the reinvented two thousand twelve Camray. It's ready. Are you get in touch with technology? With tech Stuff from how stuff works dot com. Hello everyone, welcome to tex Stuff. My name is Chris Pollette and I am an editor how stuff works dot Com, sitting across from me, as always his senior writer, Jonathan Strickland, logic clearly dictates that the needs of the many outweigh the needs of the few. Okay, so today we're going
to plug Thank you. Today we're gonna talk about logic gates. But before we get started, let's let's let's begin with a little Facebook feedback you. This comes from James and James's suggestion Electronics one oh one logic gates. Thanks James, it was an easy one. Yes, we're going to tackle that, but before we do, I have a little listener mail. This listener mail comes from Chris and not the Chris
who's sitting across from me. Chris says, you say in your three hundred episode that machine code can't be easily read by humans. That got me thinking humans made machines. I understand that the best concept at the time was to code computers and machines with this complicated and unreadable language. But in this day and age, why don't we build
computers and machines that can understand our language. It just seems to me that some kind of cycle humans build machines that only understand a complicated language, we adapt to that language, and we build programs that translate a simpler language to the machine language. Is it possible for computers and machines to be built to process information in the languages we are accustomed to? Now these two items are
actually related to one another. You might think, well, one of these we're talking about natural language, and the other one we're talking about logic gates. How do those end up being related? Well, it's because machine code is based upon the binary system zeros and ones and logics are as well. And it turns out that the way we've built computers is based upon this binary system, and that's
why we have machine code. It's this two humans. It's a it's a complex way of trying to get a machine to do a relatively simple task, or at least one that seems simple to us. And unfortunately, there is not an easy way to translate natural human language into machine code in order to make a machine understand natural language in a on a fundamental level, like on a mechanical level, we would have to completely change the foundation of computing. Yeah, so that's why it's a big deal. Uh.
You know. Instead, what we do is we end up building programs that can understand on on a superficial level what natural language is and translated into machine code so that a computer can respond the proper way. It's not true understanding, because again, a computer is just running processes. It's just running, uh, series of calculations using these zeros and ones and logic gates are the very foundation of that. It's the foundation of circuit treats, the foundation of electronics,
and the foundation of computers. But it kind of goes back a long way back, in fact, before there were electronic computers. Oh yeah, I mean, because you know, I I think of it as, uh, well, we actually have an interesting article about it, um about something that has come up with a couple of centuries ago by a
guy named George. Yeah you know. Oh yes, because logic gates operate using Boolean logic, we have then there is an article on how Boolean logic works, on how stuff works dot com, I recommend actually, which is basically about logic gates, which is kind of funny. I had no idea until I started doing research on it um because we also have a an article about how electronic gates work on the the the site. But there's they're sort
of hand in hand. It's better probably to go back through the bully and logic article first and then go to the other um. But yeah, I mean, he basically figured out how to use uh, you know, I guess it's sort of the marriage of language and mathematical operation in some ways, wouldn't you say? Yeah? And I also tend to to relate it back to symbolic logic, which
is another way of marrying mathematics with language. Now, if you're not familiar, symbolic logic is a concept where you reduce statements to sort of almost like an equation, and using the equation form, you evaluate that statement to determine whether or not the statement or the combination of statements
is true or faulse um. And you know, you have to make some certain assumptions in order to do that, but you can build more and more complex equations using all these series of statements to determine if the ultimate conclusion is true or false, and by true or faulse, we're really talking about whether the argument holds water or not.
So you can actually do this. You could take a debate and you could take one person's side of the debate, reduce it to this sort of mathematical equation, and then determine whether or not the ultimate outcome of that of that person's side of the debate makes sense from a logical standpoint. Yeah. Now again we're talking logic here. We're not talking about, uh, you know, trying to get someone to agree to something based upon its emotional weight, but
simply does this argument makes sense? Does it follow the rules of logic? Yeah? And a lot of these UM when we talk about the logic gates UM, they're actually devices inside electronics that use these logical operators, these rules, these rules within the machine. Basically, they're passing instructions based on the type of circuit they are and according I actually look this up in Access Science, which is UM
a really awesome database for for technical things like this. UM. Basically, the Access Science said that if you're creating a gate circuit UM, they could be made up of transistors, diodes,
or resistors, in some combination. Now most today are are generally transistors only, but they could be made up a variety of components um and they're they're basically, you know, you hook these up, and you can hook them up in a variety of different ways depending on the type of device and what you're trying to get it to do. Um it. We'll get into that later, but basically, these circuits are um a series of components that are wired
together to perform a logical operation within a device. So let's start off from the very very very basic steps. So it all begins with bits, zeros, and ones. Now this these aren't just numbers zero and one does not that doesn't that to us, That doesn't really mean anything other than the fact that we can do mathematical processes using them. As as as values zero and one um they actually translate into other concepts. So a zero in an electronics system would be a low voltage meaning zero volts,
and a one is high voltage, meaning five volts. So a one means you've got electrons running through there at five vaults. Zero means there are no electrons running through zero vaults. But a zero also would mean a false statement. One means a true statement. Zero could also be thought of as being on in the off position. One is in the on position. So let's we have to do. You know, zero and one is kind of shorthand of saying. So if we're talking about zeros, we're talking about false,
and we're talking about once, we're talking about true. For time about zero's we're talking about low voltage. If we're talking about one, we're talking about high voltage. This is how we translate ideas conceptually into a real device, a physical device that does something one there we go true. So now a logic gate will process a signal and what it does to that signal, like it has an input and an output, what it does to that signal when it comes in through the input is based upon
two things. The nature of the logic gate, because there are several different basic types of logic gates, and the whether or not the input was true or false, so whether or not it was a one or a zero. Those two elements will determine what the output of that specific logic gate is. And the simplest logic gate is a not git that's also known as an inverter. Yes, Now inverters what they do is, they will take an
input and switch it to the opposite output. So, in other words, if a zero is fed into a not gate, it will produce a one. So false statement comes into a not gate, it flips it to a true statement coming out right, all right, so or against low voltage to high voltage, yes, vice versa. So whatever the signal coming into the the not gate is, the opposite goes out. Now it can only have one input, which makes it
unique among the gates. The other gates have two or more inputs, and they combine the two in order to produce a result. Alright, So then the next one would be an and gate. Now and gates will produce a true result only if both inputs coming into the gate are also true. I think of that like the programming statement if then if both are true, then it will return true results. So that means that let's say imagine
that you have this. You can actually imagine that this is a gate and there are two roads leading into the gate, and you have two cars going up to the gate. If both cars are are true, then you've got a true result coming out. Otherwise you have a false result coming out. Actually, it would be and if and only if yes. So, in other words, if you have to If you have these two uh inputs coming into the and gate and both are a one, so both are true, both are high voltage, you get a
one as a result. Any other combination you get a zero as a result a false statement or low voltage. Zero and one will equal zero. In this case, zero zero will be zero, zero one will be zero, one zero will be zero because you have to think of all three instances that way. Even though you might say, wait, zero one and one zero, isn't that the same thing? No, Because you're talking about two different inputs coming into a gate, and those two inputs are coming from two different sources.
Sometimes yeah, sometimes they come from the same source, but usually they come from two different sources. And that means that because they're coming from two different sources, you have two different configurations. You have one where one is true and one is faults, and another one where one is faults and the other is true. Sounds kind of complicated, it's actually pretty simple. And again, if this starts to sound confusing, check out these articles that we have on
our site because they will help illustrate these concepts. So, besides the end gate, you have the nand gate or not and now and not and will produce a true result in every case except where both inputs or more are true, because you can have more than two inputs in an end or a nand gate. So in other words, if you have two zeros, a zero, one, or a one zero, you're gonna get a one out of a
nand gate. If it's a one and one, it's going to come out as a zero in a nand gate, right, Then you've got the or gate, and or gate will produce a true result if at least one of the inputs is true, so zero, one, one, zero, and one one will all produce a one. Only zero zero produces a zero or a false statement. Then you've got the Nora gate, which is not or It will produce a true result if both inputs are false, so zero zero will produce a one zero, one one zero and one
one will produce a zero. Then you have now all of those gates, the the and nand or and nor gates can receive multiple inputs. And in order to really kind of sort this out, I know it sounds confusing, you can actually build a truth table. A truth table is essentially just a it's like it's almost like a spreadsheet, and it shows you what each scenario, what the outcome would be for that particular scenario for that particular gate.
So like if A equal zero and be equal zero, results C will equal whatever I should say result Q because that's typically how they label it in uh in diagrams. Yeah, they usually use a que to differentiate, so there's no confusion that it's zero. They they you use a que so that you get the ideas. Oh yeah, that's the output. Um yeah, I was just gonna say that truth table kind of sounds like a medieval torture device. Him on the truth table, nobody resists the machine. I really don't
know what that would do to you. Um Now I just quote Princess Bride, but of this, I was gonna say that there's an extra bonus movie quote. Remember this is for posterity, so please be honest. There are two more gates. Two more gates. Yes, there's X or the exclusive or gate, which produces a true result if the two inputs are different. So if a zero, zero or one one comes into an ex or gate, you're gonna get a zero, right if you get a if it's one zero or zero, one going into an ex orgate
get a one. Uh. Now, because of the nature of this gate, it can only accept two inputs. You cannot you cannot have multiple inputs beyond two in an x or gate because it has to be specifically geared that way. Right, because because it has to be if it if it's if, if they have to be different. Uh, then there are only two choices, right, there's a zero, there's a one.
If you have three inputs going into something and they have to be different and there's only two choices, there's no way two of those inputs have to be the same. Bye bye again following logic. So therefore, and an ex or gate, only two inputs can go into that gate. Then you have the x nore gate and it produces a true result if both inputs are the same. So if a zero zero or a one one goes into an exnore gate, you get a one. Otherwise you get a zero. Same thing as the ex or gate in
that you can only have two inputs going into that gate. Now, using these gates that we have just described here, if you build you can actually build up a circuit using those as their basic building blocks. In fact, you can go to a hobby store and buy chips that have
logic gates built onto them. Yes, and we were talking about the the RDU know a few weeks ago, And these are the kinds of projects now if you can get a basic grip on this, these are the kinds of things that you can add to your projects if you're doing um hobbies yourself and want to do this. Now, you know, once you get a basic understanding of this, you can make much more complex projects. Yeah, so, uh you know, we you can consider building a circuit using
this as as using combinational logic. You're combining various gates together in order to get a different results. So you might have three inputs going into a system, and then you you align various gates in a very in a particular sequence in order to get a different result, and it all will obey the laws of the truth tables. Now, these these circuits can get pretty lunkey and pretty complex, which is why we've sort of abandoned the uh you know,
it works great as a concept. In reality, we've virtualized a lot of this since then because it just otherwise it would just be a massive piece of hardware in order to build a really really complex circuit um. But you you can actually lay these out in various configurations
to get different results. So it might you might have uh two inputs going into and and UH gate and another input going into a not gate, and then those the results of those um of those particular functions will go into a third gate and then now that way you have something coming out like maybe the maybe those are both going into an ex or gate, and then whatever the result is is what you're looking for. Uh. These,
like I said, get pretty clunky pretty fast. The interesting thing is you can actually replace the function of some of these gates using other gates. You just have to put them in the right configu duration to do so. So you can think of some of these gates is almost being like shorthand like this gate does this one function and so therefore uh it does it um. You know, that's all it does. You just put that in this place.
But sometimes you might be working with a system where you don't want to have lots of different types of gates. You want to use maybe one or two types of gates and you don't want to have to deal with all the others. Well you can do that. You just have to build the gates in the proper sequence in order to get the result you want, UH for it to to copy the function of one of the other gates.
And there's various ways of doing this. Now, it does mean that you're going to use more gates overall usually than you would if you were using the the different types, but you would all be using the same type of gates. So you're you've reduced it to a single type of gate, but you you're using more of that particular gate than you would if you were using multiple types of gates.
Sounds a little complicated, but it does. It does mean that when you're sketching it out, it really cuts down on the sort of gates that you have to design when you're when you're at least conceptually building your circuitry. Now, go ahead, and I was just gonna say that these these gates can be run in parallel or in a series, and um it actually kind of reminds me in a way of a very complex UH railway, because I mean, you're basically using these switches to control the flow of
information in your electronic device. Um So as a you know, as someone would watch the board and make sure that the trains don't collide. Um. You're also sort of you know, you can actually control the way information flows through the device using these switches, and you can place them in ways that make the most sense to to what you're trying to carry out, which is essentially what you just said.
But um, it helps me think about this conceptually, to put it in and out analogy from that to something that I can think about, like trains, because trains are nice and and if you wanna, you know, if you really want to get into this, each of these gates has a particular um graphical representation of you know, what it does. So it's I'm not bothering describing it on the podcast because this is an audio podcast. It would be kind of it would be kind of pointless to
do it. And the shapes, the shapes aren't you know, like a circle or a triangle or a square something that is uh easy to describe, a lot of these shapes are modifications of those types of things. So you might say a trianglar looking thing, but you're really not going to get it. It makes more sense to actually go to a website that has them all laid out, and then once you learn what the the sort of
graphic representation of a gate what it looks like. You can start looking at um the combination of gates and say, oh, well that's an and gate. So that means that since I know that and gates always give a result, that is, it will produce a true result only if both inputs are true. I know what the output of this end
gate will be depending upon the inputs. So, because it's always going to behave the same way, it's never going to behave uh in a way opposite or different unless you you know, well never, it will never do that. It's only if you were using a nand gate that it would be different than the way it normally is. UM. So that way, since you know how each gate behaves in any specific circumstance given time, you can decipher what a fairly complex diagram will do. You just say, all right,
I know that this gate always behaves this way. Therefore, this is what would happen given this particular series of inputs. You can actually build out a truth table for a complex circuit that way, and you will ultimately know what
the circuit will produce given any particular set of circumstances. Now, the more complex a circuit gets the wider that truth table is gonna be, and the more you're gonna have to really check to make sure you're following the logical rules so that the results are are accurate, um other and we call this, we actually call this programming a circuit. Even though you might think of programming is something you
do sitting down typing on a keyboard. This and this involves actual physically hooking up wires to logic gates in whatever sequence or series you need. Uh, we still call that programming. Yeah, an engineer might graft this out using these symbols on a piece of paper to get an idea of how it works. But logic gates can be very very small. I mean, we're we we've talked about
the manufacture of transistors before. I mean, you can have millions of transistors and a very small piece of silicon and the logic gates I mean, using the metal oxide semiconductor UH type, which is apparently predominant according to Access Science and manufacturing today, you can have many, many of these devices. So it helps I mean, I think it would help me if I were trying to figure out exactly how I wanted to lay out this device to have it you know, drafted out with these symbols and
get an idea of how it's it's working. I'm sure a lot of them use computers. Actually have a program that I use for information architecture that has a template with all these symbols on there, and then you can, you know, put it up on the screen and get an idea of how it works. But that's far larger than the actual devices because the manufacturing process can make them very very tiny, right, And as we've said in other podcasts, this is part of why miniaturization has some
uh some challenges, uh that go along with it. I mean, there are a lot of different challenges, but one of the challenges is that by getting these gates to be smaller and smaller, each each element on a transistor is
decreasing in size. Remember, if we're following Moore's law, then ideally you're going to be able to fit twice as many discrete elements on a chip within twenty four months, or at least the the number of discrete elements on a chip will be twice as many as it would have been twenty four months before, so two years before um with that, with those elements decreasing in size. At that pace, you start to run up against some pretty challenging issues and we've talked about it several times on
the podcast before, Like electron tunneling. So if you have a gate that determines how what the result it needs to be from any given inputs, um, if you have an electron that can tunnel past that gate, then it overrides the function of that gate, which means it will start creating errors in your calculations. You know, you think about these these gates being so small that electron can
tunnel through them. And by the way, electrons don't really tunnel through them, they just appear on the other side of the gate. Actually, if you think of it this way, think of as an electron as just being a uh. It's you can predict that electron will appear somewhere within a given area, all right, but you don't know the specific location of that electron. So within a given area, think of it like a sphere. You've got the sphere,
and somewhere inside that sphere is this electron. Right as that sphere approaches the gate, then part of that sphere is going to go over the gate. Uh and meaning that the electron could in theory somehow exists on the other side of that gate without passing through it. That means that because there is a chance that the electron could somehow exist on the other side of that gate
without passing through it, sometimes it does. Because there's a chance, yes and anything that if there is a chance for something to happen eventually, sooner or later, it happens. So that's the definition of chance. If there's no chance that it won't happen. So right, exactly, there's Schrodinger shake fist. Actually it's more like Heisenberg's and certainty principle. But anyway, um, but I was thinking you just weren't sure about it,
right exactly, there you go. So anyway, the electron, because it can sometimes be on the other side of that gates. Sometimes it is on the other side of that gate. That's one of the challenges we have when we get these these gates at these tiny, tiny size. You know that the thickness is not thick enough to prevent electron tunneling unless start switching to other materials which are more resistant to electron tunneling, which is so complex. I still have not gotten a good grip on it. So I
can't really explain why that is. I just know that really smart people at Intel have figured it out. Anyway. Uh, that's one of the reasons why we talk about this miniaturization process being a challenge to keeping Moore's Law going because remember More's Law is not truly a law, it's an observation, and companies are struggling to make sure that they meet the expectation laid out in that observation and
self fulfilling prophecy. Yes, yeah, because once More's Law ends, then you know, the chaos will rain and robots will take over the earth and etcetera, and zombies and brains anyway. So um again, because logic gates are the very basis of these calculations. If the electron ignores the logic gate,
computing stops working. So that's why we talk about electron tunneling, quantum mechanics, and quantum engineering in relation to microprocessors, because they're built on this foundation of logic gates and they are basic. Microprocessor is going to be so complex that to sketch it out and a logic gate formation would
be pretty intense. But the nice thing is you can learn the basics of this pretty simply, like I said, you go to a couple of websites and look at how the logic gates are are displayed in a in a sketch. And you can even go out to a hobby store and buy chips that have logic gates on them and learn how to hook them up yourself and see it in action. It's pretty cool. It's a it's
a neat project. There's a neat way to really start getting your feet wet in designing electronics, and there are plenty of different tutorials out there to explain how to do that and what why you would do that, Like you know, yeah, I've hooked up a lot of wires to this thing and it's doing this thing, but I have no idea why it's doing it or or what's
the purpose. This is just the foundation, the building blocks um and then hopefully maybe in the future podcasts we can go into stuff like sequential logic, as we're talking about combinational logic right now. Sequential logic depends on other concepts like state, like an information state. You know, we say that an information has state if it carries over information from previous calculations. If I were to give you
a simple calculation. If I were to say, all right, add one variable to another variable and you get a sum of those two variables. All right, Well, there's no state in that in that function I just gave you, because you could take any two variables you wanted and
you're going to get a sum. But there's that that sum has no information on it based upon the previous two numbers you added to it, right, Because you might say, all right, for this one, I'm going to add three and four I got seven, And this one i'm gonna add five and nine I got fourteen, and they have no bearing on each other. Information that has a state has bearing upon previous calculations, and that's very important for computing.
Without it, computers would own we be able to do really one function and then the next function will have nothing to do with the next uh with the with the one you did before. So it would be impossible to really build a program. You would have to have something that has some form of state so it can build upon what has come previously. That really goes into
sequential logic. It's its own thing. We will tackle that in a different podcast, because that's gonna have some more kind of complex conversations to kind of get into you know, what sequential logic is, what it means, and how do we achieve it. But but really you can't get there without first looking at the logic gates issue. So I want to thank our listeners who have requested logic Gates because it is a really important topic. It's a really
fun topic really if you like puzzles. I I was telling Chris before this that symbolic logic is one of my was one of my favorite classes in college. I was in English literature major with a focus on shakespearean uh drama, but somehow symbolic logic became one of my
favorite classes because it just made sense to me. And I love these sort of puzzles where you just you look at this big picture and it looks really complex and really overwhelming, but if you just know the rules, with enough time and attention, you can figure out how it all works. And that's amazing. I don't know, I'm pretty illogical. I'm not sure. Well I I when I'm saying you, I really mean me, I don't mean you you Okay. So anyway, that covers our episode on logic gates.
If you have any requests for particular episodes, whether they be really technical or not so technical, just let us know. You can say as an email that address is tech stuff at how stuff Works dot com, or you can send us a request via Twitter or Facebook or handle
at both of those is tech Stuff h SW. And we should also point out recently we launched a brand new iPad app, So if you are an iPad owner like the fellow sitting across the table for me, and you want to have some fun with a new app that has a lot of our great content all bundled in their specifically designed for the layout on the iPad, check that out because it's been, uh, it's been really impressing everyone around the office for a couple of weeks, and now that it's out there in the wild, we're
really excited to see what people think. And Chris and I will talk to you again, hopefully with a little bit of logic really soon. Be sure to check out our new video podcast, Stuff from the Future. Join How Stuffwork staff as we explore the most promising and perplexing possibilities of tomorrow. The House Stuff Works iPhone app has arrived. Download it today on iTunes. Brought to you by the reinvented two thousand twelve Camray. It's ready, Are you
