Logic gates.

Conjuring images of Tron-like circuitry; tiny shards of electricity whizzing through infinitely complex systems of on/off switches, letting you use MS Office, browse the internet, and play Skyrim with Thomas the Tank engine mods, these little guys are at the base of all computers.

Modern Computing: brought to you by your friendly neighborhood logic gates

All of the processes computers run to from making goofy Skyrim mods to running a complex gene sequencing program to sending an e-mail to your mom (email your mom, btw), come down to configuring obscenely simple logic gates in more and more complex ways.

Yeah, I said it. Logic gates are simple.

Just as making a fancy souffle or creme brulee is a combination of complex steps using simple, normal ingredients, so are a computer’s processes made of combinations of simple gates in complex steps using relatively simple ingredients: logic gates.

In (non-quantum) computing, the fundamental type of logic all computers use is called Boolean logic. Boolean logic boils down to true or false, or put another way, on or off. Logic gates contain switches that fire based on if the electrical current inputs are strong for true or weak for false; also known as on/off. (True = on, false = off).

For example. One type of logic gate is called an “and” gate. I’m going to draw it as taking in two inputs, a and b, and giving out one output, called “out.”

And gate

This And gate outputs ON if both the inputs a AND b are also ON. Otherwise, it outputs OFF.

To visualize this in a table format (also called a truth table), using 1 to represent ON and 0 to represent OFF, it looks like this.

A truth table for an AND gate that takes two inputs

In Pseudocode, we could represent this function like this:

if (a==1) AND (b==1)  then out=1 else out=0

To get more and more complex functions and outputs, we can chain different gates together to get the desired outcome. The chaining together of the gates certainly can become complex very quickly, but the gates themselves always boil down to simple expressions of boolean logic.

What if I want to add another input to my AND gate? Well, its simple. The AND gate takes two inputs, so, I make a gate chain using another AND gate. It looks like this:

Using AND gates for three inputs

Represented in pseudocode, it looks similar to the basic if/then logic represented above:

if (a==1) AND (b==1) AND (c==1)
then out=1 else out=0

I’ll bet you know where this is going. To make more complex functionality, the simple gates are chained together to allow space for the logic gates to compute their tiny, individual part of the process.

There are several different kinds of gates, AND, NOT, XOR, NAND, etc, but the best thing to keep in mind is each of these gates takes a certain input, uses boolean comparisons to evaluate the inputs, and outputs a value. To get more complex functionality, these gates begin to work together in a composite or “chained” style, but the gates themselves stay very simple. We’ve only shown examples using an AND gate in this post, but for further understanding and to get your hands dirty building your own gates, I recommend checking out the Coursera course “Build a Modern Computer from First Principles: From Nand to Tetris (Project-Centered Course)” from the Hebrew University of Jerusalem.

Tl;dr: Logic gates are simple, boolean logic evaluators that can be chained together to allow for more complex processes.

I make things, sometimes with code :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store