Ground Up: Bits

Welcome to a new series of posts cleverly titled Ground Up, where I explain computing concepts from the ground up! We’ll explore how computers work starting with transistors and going from there. This post specifically covers transistors, digital logic, and binary.

Transistors

At the end of the day, computers are complex circuits built mostly of transistors. Transistors are electrical components that can be thought of as gates that allow or deny current to flow. That’s it. Try toggling the gate below to see how the current responds.

It is from this simple building block we can begin to form more complex logic. There are two common variants of transistors: P-Channel and N-Channel. The above is an N-Channel transistor, which means the current flows when voltage is applied to the Gate (G). A P-Channel transistor means the current flows when there is no voltage applied to the Gate.

The dot on the input gate indicates negation and is a common symbol in digital logic. It helps me to remember that the P in “P-Channel” has a hole in the letter like the dot on the schematic.

Binary Logic

Before we start using these building blocks, let’s cover what binary logic is. Through the transistor, we have a way to allow current to flow or not, which can be thought of as two states: on or off. When the voltage in a circuit is above a threshold, it is considered to be “on”, and when the voltage is below a threshold, it is “off”. This is the basis of binary logic: there are only two possible states the circuit can be in. From here on, we’ll denote “on” with a 1 and “off” with a 0.

NOT is the simplest binary operation, involving only a single input. The NOT operation will negate its input. If the input is a 1, the output is a 0. If the input is a 0, the output is a 1. Below is a table of binary operations for your reference.

Binary OperatorSymbolDescriptionTransition Table
NOT~Negate its input
AOutput
01
10
AND&Outputs 1 if both inputs are 1
ABOutput
000
010
100
111
OR|Outputs 1 if either input is 1
ABOutput
000
011
101
111
XOR$$\oplus$$Outputs 1 if its inputs are not equal
ABOutput
000
011
101
110

Great! Now you may be wondering why this is useful. Well, you can actually build a lot of interesting things just from these components alone, including memory, state machines, and eventually computers.

Using Transistors

Let’s now build the components that will perform these binary operations using the only building block we have: transistors! I highly recommend you try this exercise on your own before seeing how I’ve done it here.

This online simulator is a good tool you may use. The components we are using are the N-Channel and P-Channel MOSFETs (under Active Components).

Electronics Introduction

For those new to electronics, here are a few notes to help you build the below circuits.

Transistor Characteristics

Because N-Channel and P-Channel transistors are electrical components that abide by the laws of physics, there are some restrictions on how they can be used in circuits. They are not completely binary in allowing current to flow or not, and it actually depends on the “Gate to Source” voltage. The important thing to note is that N-Channel transistors should source low voltages, and P-Channel transistors should source high voltages. You will notice in the examples below that all of the P-Channel transistors are on the “top half” of the circuit and all of the N-Channel transistors are on the “bottom half” because of this.

This limitation also results in inverse operators being easier to build than their logical counterparts. To build an AND gate in practice, it is a NAND gate (NOT-AND) followed by a NOT gate.

NOT Gate

Instructions: toggle the inputs to see how the circuit reacts.

Out
01
10

AND Gate

Out
000
010
100
111

OR Gate

Out
000
011
101
111

XOR Gate

Out
000
011
101
110

Note: The bars over the label indicates negation. For simplicity I removed the transistors to calculate that from A and B.

More Bits

Just as a note, these components operate on at most 2 bits, where a bit is a 1 or a 0. As we build components up, we will want to work on larger groupings of bits, and it should be known that these operations can be applied in a bitwise fashion. You can AND two 4-bit inputs by using the AND operation on each pair of bits. For example 0110 AND 1100 would be 0100.

Bit 3Bit 2Bit 1Bit 0
A0110
B1100
Output0100
{: style=“width: 50%;”}

Conclusion

This post covered the very basics of computers: transistors, digital logic, and binary operators. If any parts were unclear, please feel free to contact me.

[Take me to the next part!]({% post_url 2021-07-06-ground-up-gates %})