What exactly is in a 1 bit of digital memory?

Rukshani Athapathu
Coder's Corner
Published in
12 min readNov 9, 2017
Source : giphy.com

We often say that computers only understand ones(1s) and zeroes(0) and in our day to day programming life, more often than not, we talk of byte streams ‘coming and going’ when we try to explain one thing or another. But have you ever really thought about what exactly these 1s and 0s are? We often imagine them running around wires, don’t we? Is there really something that moves around? Well, there is, but not what you think. So let’s dig in.

Well, we are going to have to examine things in a molecular level if we truly want to understand what’s in a one bit of memory. We will get to that in a minute. But before that, there is something else that we need to understand first.

Transistors” — The invention of the transistor has been one of the major milestones in the history of science and it has revolutionized the technology that we use today. Simply put transistor has been regarded as the singular most important invention in modern history. If you take a look inside a processor (for example a processor in your computer or your smartphone), you will find billions of transistors there. Of course, they are microscopic. But what do these transistors have to do with bits? Well, everything! And you will see how.

Let’s build a 1 bit of memory

Let’s start from the beginning and we will slowly build a theoretical bit . I’m going to explain everything down to it’s atomic level, so there’s really no excuse for you to not understand this :)

It all starts with Silicon

Silicon makes up 27.7% of the Earth’s crust by mass and is the second most abundant element (oxygen is the first) on earth according to Royal Society of Chemistry. But what we are interested in it’s semiconductor quality, that is, it’s ability to conduct and control a flow of electrons, which in other words an electric current. Just imagine 6.24 x 10¹⁸ number of electrons passing a single point within a second and that’s one amp(ampere) of current you have there.

Now let’s take the silicon element and get down to it’s atomic level and explore what’s really in there.

Image Courtesy: www.homepower.com

You don’t need to understand everything that is there in the above diagram. Just observe the outermost shell which is also called the ‘Valence Shell’ and you will see 4 electrons in it. This valence shell can be transferred or be shared with another atom and because of that, each silicon atom is actually bonded with another 4 neighboring atoms and we call this a ‘covalent bond’.

http://hyperphysics.phy-astr.gsu.edu/hbase/Solids/sili.html

The point is, if this pure silicon is to conduct electricity, it has to have some free electrons to move about. Therefore these electrons have to absorb some energy to get themselves free from their covalent bond. So pure silicon is pretty much useless in it’s original form.

So what’s the solution? — Doping

Therefore to improve the conductivity of the silicon, a technique called doping is used by mixing a small amount of impurity into a silicon crystal. There are actually two types of dopings.

N-type doping

https://www.science.org.au/curious/technology-future/solar-pv

If we inject silicon with a substance like ‘Phosphorus’ that has five electrons in it’s outer shell, then one electron is free to move. Since electrons have a negative charge we call this N-type doping.

P-type doping

https://www.science.org.au/curious/technology-future/solar-pv

Now if we inject silicon with a 3 valence electron like ‘Boron’ now there’s a vacant position(hole) for an electron in the lattice. This absence of electrons create a positive charge, hence the name P-type and remember now the neighboring electrons can fill these holes at any time.

Combine P and N type and you get a “Diode”

A diode

If we inject one part of a silicon wafer with Boron and other part with Phosphorus, we can create a diode. That is, one part will behave as a P-type and the other part N-type and if we place these two parts adjacent to each other we get a P-N diode.

Now, on the N side we have free electrons to move and on P side there are holes. So what do you think will happen at the boundary of P and N?

Well, abundant electrons from the N side will try to migrate to the holes in the P side to combine with them, leaving the N side slightly positively charged while making the P side slightly negatively charged.

This situation will result in an electric field called ‘depletion layer’ which will oppose any further natural migration of electrons, making it a barrier to flow any current through it.

Reverse Biasing

If we apply an external power source as in the above diagram, right end of power source will attract the electrons and at the other end electrons will try to move away from negative terminal (because electrons repel each other since they both have a negative electrical charge) leaving holes there and this will make the depletion layer to get widen. So now it is impossible for the electricity to flow through the diode.

Forward Biasing

But if we set up the power source other way round, then the situation becomes quite different. If we assume the power source has enough voltage to overcome the barrier, electrons that are pushed away from negative terminal will cross the barrier and will get attracted to the positive terminal and that will make the current to flow. This is known as forward biasing.

Transistor is born!

If we attach three layers in N-P-N fashion, we call that a transistor. If you closely look at the diagram below, you will see that we have two diodes here. N-P and P-N. However, no matter which way we connect the power source, no electricity will flow through the transistor because one diode will always be revered biased.

Naming should be N-P and P-N… My mistake

But there is something that we can do to make the current to flow through the transistor. Trick is to apply a small current to the middle layer and it will amplify the current that flows as a whole. But how?

Assume that the second power source that we have attached has enough voltage to overcome the barrier at the N-P junction. So now, this is just a forward bias. So now the electrons from the N region will start to move to P region and few of them will flow across to the second power source while a much larger number of electrons will get attracted to the positive terminal of the first power source (Reason for this is the narrowness of the P region). So that’s how we can amplify the current.

Another important thing that we can do with the above circuit is, based on the voltage of the second power source we can control the current that flows through it. Simply put, we can make the transistor to go ‘on’ or ‘off’. How do we do that? Well, you probably might have guessed. If the input voltage of the second power source is not enough to overcome the potential barrier, simply the current will not flow.

So based on the voltage, now we can control the transistor to be ‘on’ or ‘off’ and that opened the door to the ‘digital memory’. But we are still far away from making that 1 bit. So hold tight.

On a side note, please be informed that there are two types of transistors called Bipolar Junction Transistors (BJT) and Field Effect Transistors (FET). The transistor that we talked about is of type BJT. We are not going to go into details about these types, it’s out of scope. It’s enough to have a very basic idea of a transistor for our task of building 1 bit of memory.

In electronic circuits, the above transistor is represented using the following symbol.

Transistor

Now enters the NAND gate!

We know, that if there’s no voltage at the base, current will not flow from C to E, that is the transistor is off at that point. But if there is a positive voltage at the base then the transistor is on. Now let’s use two of these transistors to build a NAND gate. NAND gate is one of the most significant logic gates there is, because all the other gates (OR, NOT, AND etc..) can be build using a combination of these NAND gates.

Now we will examine what’s the output gonna be for different transistor statuses. We will represent the presence and absence of current at a given point with ‘1’ and ‘0’ respectively.

  1. When both transistors are off, current will flow through the output, not down the transistors. So output is ‘1’.
  2. When only ‘b’ has a positive voltage, current from the 5v still can’t get pass the transistors but the output will have current. So output is still ‘1’.
  3. When ‘a’ has a positive voltage, current will get pass the first transistor but not the second. But still there’s positive voltage at the output which in other words it’s still ‘1’.
  4. When both ‘a’ and ‘b’ has positive voltages, current will flow straight down the transistor so output will be ‘0’ this time.

So, if we summarize the above points in 1s and 0s, then we get the following truth table for NAND gate.

Truth table for NAND gate

The NAND gate usually represented in following symbol.

So, this is all we need. Wire 4 of these NAND gates in a specific format as in the following image and we will have our 1 bit of memory. (Note : Following information I have gathered is from this wonderful book called “But, How Do It Know” written by J. Clark Scott. If you want to know more, go read that book.)

Source

Back to the subject. Now let’s see how we can use this to simulate 1 bit of memory.

i — Input bit that we want to remember

o — Output of the remembered bit

s — Input that tells the gate, when to set the memory

There are four situations that we need to examine here. I have copied the same image in each section to make it easy for you to understand the logic.

When s — on with i — off [What is the output?]

Bit status at each gate,

Gate 1 : s(1) i(0) — — — — — — — — a(1) — on

Gate 2 : a(1) s(1) — — — — — — — — b(0) — off

Gate 4 : b(0) — — — — — — — — — — c(1) [since one of the input to gate 4 is 0, according to NAND’s truth table we know that output at c will be 1]

Gate 3 : c(1) a(1) — — — — — — — — o(0) — off

Gate 4 : o(0) — — — — — — — — — — c(1) — still on

Answer : s — on, i — off, output — off

When ‘s’ is on, output will be same as ‘i’.

When s — on with i — on [What is the output?]

Bit status at each gate,

Gate 1 : s(1) i(1) — — — — — — — — a(0) — off

Gate 2 : a(0) s(1) — — — — — — — — b(1) — on

Gate 3 : a(0) — — — — — — — — — — o(1) [since one of the input to gate 3 is 0, according to NAND’s truth table not matter what the other input is output at o will be 1]

Gate 4 : o(1) b(1) — — — — — — — — c(0) — off

Gate 3 : c(0) — — — — — — — — — — 0(1) — still on

Answer : s — on, i — on, output — on

When ‘s’ is on, output will be same as ‘i’.

When s — off [What is the output?]

No matter what ‘i’ is, ‘a’ will be on since ‘s’ is off.

Gate 1 : s(0) — — — — — — — — — — a(1) — on

Gate 2 : a(1) s(0) — — — — — — — — b(1) — on

Now ‘a’ and ‘b’ are both on, so what will be the output? Now to find ‘o’ we have to consider the situation before ‘s’ got turned off.

If ‘i’ and ‘o’ were both on before ‘s’ got turned off, ‘o’ is on. How?

Gate 3 had a(0) c(0) — considering previous situation of ‘o’ as on

Gate 4 had b(1) o(1) — considering c is off

So, when s(o) for ‘b’ to be ‘1’ → ‘a’ has to be ‘1’’

but still ‘c’ is ‘0’ hence at Gate 3 → a(1) c(0) — — — — — — — o(1)

If ‘i’ and ‘o’ were both off before ‘s’ got turned off, ‘o’ is off. How?

Gate 3 had a(1) c(1) — considering previous situation of ‘o’ as off

Gate 4 had b(0) o(0) — considering c is on

So ‘o’ stays off.

Answer : When ‘s’ is off output stays the way it was and will not get affected by ‘i’.

Conclusion

For simplicity sake, let’s represent these 4 NAND gates in following symbol. This is in fact our memory bit.

Source

We have input(i), controller(s) and output(o).

We have seen, when ‘s’ is on, ‘o’ does what ‘i’ does. When ‘s’ is off, ‘o’ stays the way it was before ‘s’ went off. So when ‘s’ is off, even if ‘i’ changes, ‘o’ stays put. And that is how we can save the status of a bit that was set at some point in time.

So what exactly is in a 1 bit of memory? In J. Clark Scott words,

A bit is just a place. It is nothing more than electricity being on or off. If there’s no electricity in that place, then the bit is off. When electricity is present then the bit is on. So the only thing the computer can remember is whether the bit was on or off.

Now you see why people often say that computers can only understand 1s and 0s [1 — on , 0 — off].

That’s the mystery of “1 bit”. Hope you enjoyed!

Summary

Silicon → doping → diodes → transistors → gates → bits

Note: If you are interested in seeing a transistor level simulation of a CPU, check this out. Following is only a still image of that, you can try the real simulation by following this URL. But be cautious though, it eats up a lot of memory.

http://visual6502.org/JSSim/index.html

References

--

--