This video does great work in explaining how diodes and transistors work. It should be easy to understand after reading the above-mentioned part 1 and 2. The part you should take note of is near the end of the video, where there is talk about the transistor acting as an electronic switch.
Now lets assume the collector is always connected to a voltage source and that the emitter is connected to a small LED (and a proper resistor to keep the LED from burning). You can now blink the LED by passing current through the base intermittently. When current passes through the base, the LED lights up. When it doesn’t the LED turns off. On, Off. Hold that thought.
Boolean algebra was introduced by George Boole around a century before transistors (transistors circa 1930, Boolean algebra circa 1840). The name “Boolean algebra” was suggested half a century after Boole’s death by the way (in 1913). As far as Boole was probably concerned, he was talking about “The mathematical analysis of logic” (which was the name of his first book).
All the variables and results of Boolean algebra’s calculations were either True or False, which were usually represented by 1 and 0 respectively. The basic operators sound like logical expressions: OR, AND, NOT. To this list of basic operators I’ll add another operator, which is basic as far as everyone who deals with computers is concerned, the operator XOR (eXclusive OR).
The simplest Boolean calculations, which are the most relevant for this post, take place between two variables. Lets look at variable A and B and the results of applying different operators on their values.
The result of “A OR B” is True (or 1) if at least one of them is true, otherwise the result is False(or 0). lets mark the OR operator as one perpendicular horizontal line |. Now lets do some calculations:
0 | 0 == 0 (False OR False equals False)
1 | 0 == 1 (True OR False equals True)
0 | 1 == 1 (False OR True equals True)
1 | 1 == 1 (True OR True equals True)
Moving on to the next operator. The result of “A AND B” is True only if both of them are True, otherwise the result is False. Lets mark the AND operator by the ampersand symbol &.
0 & 0 == 0
1 & 0 == 0
0 & 1 == 0
1 & 1 == 1
Next. The result of “NOT X” True if X is False, and False if X is True. Lets mark the NOT operator by the tilde symbol ~.
~1 == 0
~0 == 1
And the last one: The result of “A XOR B” is True if A is NOT B, otherwise the result is False. Lets mark the NOT operator by the caret symbol ^.
0 ^ 0 == 0
1 ^ 0 == 1
0 ^ 1 == 1
1 ^ 1 == 0
All the above calculations form the “truth tables” for each operator (when the result of an operator is true and when it’s false).
Now lets go back to our LED. As far as we’re concerned the LED can be in only one of two states – On or Off – 1 or 0. And we have a transistor acting as an electric switch of our LED. Great, now what?
Well, what if I told you that I can make Boolean calculations just by using two voltage sources, two transistors, two NPN transistors, and get the output result using the LED? Sounds like a lot of trouble for something that one could easily calculate in his head, but bear with me on this one. Here’s a diagram of a circuit to calculate value of the OR operator:
The circuit is simple to understand. Applying voltage to points A or B will result in the LED (which is connected to the OUTPUT) to light up. A or B. A OR B. A|B. Simple. Lets look at the AND operator:
The LED will light up only if you apply voltage to A AND B. A&B.
I’ll leave it up to you to figure out how to build a XOR gate with an NPN transistor combination. It’s not as trivial as it sounds.
The above diagrams represent what is commonly known as Logical Gates, which are represented by the following drawings:
You might be thinking to yourself that there’s a huge chasm between computing as we know it and logical gates which can calculate the Boolean result after we manually mess with their inputs. We only have two pieces of the puzzle missing: The binary numeral system, and a clock. We’ll discuss the clock in the next post. Lets go over the binary numeral system first.
The binary numeral system (or binary) is simple. Each binary digit can be either 0 or 1. Lets count to 10 in binary starting from 0:
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010
As you can see, since the maximum value of a single digit is 1, once we add 1 and 1 we get 0 and carry 1 over to the left. Lets add two binary numbers and see what we get. For example 10 (decimal 2) and 1 (decimal 1). Lets re-arrange the numbers:
One can easily see that the result is 11 (decimal 3). Now one with a carry (the little b means it’s a binary number): 111b + 10b == 1001b (7+2 == 9 decimal). Simple. Subtraction works on the same principle as with decimal numbers. We’ll discuss negative binary numbers in future posts.
Now there’s one thing you might have noticed, back when we counted to 10 decimal in binary, we got an “incomplete” looking number, as apposed to 10 which looks “nice and round” as a decimal number. Lets keep counting:
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111
Which brings us to 15 decimal. The next number is 16 decimal, or 2**4, or 10000b. Notice that 2**4 is represented in binary as 1 with 4 trailing zeroes. Same thing goes for 8 == 2**3 == 1000b, 4 == 2**2 == == 100b, 2 == 2**1 == 10b, 1 == 2**0 == 1.
Base 2 (binary) and Base 16 (Hexadecimal) numeral systems are good friends. 10h == 10000b (h stands for hexadecimal). How does hexadecimal work? Lets count to 10h:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F , 10h
The little ‘h’ is important because 10h equals 16 decimal. Hexadecimal (hex) digits can also be marked by the ‘0x’ prefix: 0x13 (19 decimal), 0xab (171 decimal). If you are working with computers, you should be fluid in binary and hex. If you are running Windows, the calculator that comes with the operating system has a “programmer” mode, and works great for calculations in all bases.
Now lets combine binary with Boolean calculations to create a circuit that can calculate the addition of two binary numbers which are 2 digits wide, and display the result in binary using 3 led lights (which is enough to represent the maximum possible value for the addition, which is 6).
We’ll do this by using two approaches, lets call the first “the pure truth table approach”, and the second “the right way to do things”. Guess which one’s better. Nevertheless, for learning purposes, it’s important to take a look at both.
First lets figure out the truth table for the results. We have a total of 4 inputs (2 numbers, two binary digits in each number), which could yield 7 possible results (0-6) with 3 outputs:
A is the first number, B is the second, and L represents the 3 LEDs. Now since we only care about when each one of the LEDs will light up, we re-arrange the tables for each LED:
If we look close we can see an interesting pattern that lights up the LEDs. I’ve colored this pattern with the following colors:
Green – Only a single digits is 1.
Red – A XOR B.
Yellow – B equals A.
Orange – Only a single digit is 0.
Blue – All digits are 1.
Using some of Boole’s methods, we can translate this to a logical gate array that looks something like this:
Now here’s the same circuit with the gates colored in relation to the truth table:
Now it seems a bit too much for adding two binary double digit binary number. Lets rethink this. When adding numbers you start by adding the least-significant digits, writing down the result and remembering the carry. In binary, the result of the addition can be either 1 or 0, and the carry can be 1 or 0. If we look at a truth table of the result addition of two binary numbers, we get the same truth table as a XOR gate – The only way to get a result of 1 is to add 1 and 0. If we look at the truth table of the carry, we get the same truth table as an AND gate – The only way to get a carry of 1 is to add 1 and 1.
Translating this logic to a circuit would look something like this:
Now this makes sense. Get the TXT FILE and test it out.
If the above circuits looks familiar, it’s probably because of the image at the top of the site, showing a microscopic view of a CPU. Now consider that in the above pictures we have a total of around a 150 transistors (give or take). A modern desktop CPU has around 2 Billion transistors (with super-high-end CPUs are at 5-10 billion). No wonder your PC can run an entire operating system blazing fast while the above circuit tops out at calculating 3+3. What have though is a calculator that can add two binary numbers 2 bits wide (two digits in each number), and output a results 3 bits wide.
But one thing is missing. We are still manually flicking the switches. In the next post, we’ll bring this beast to life with the addition on the clock.
This was a heavy post, but I hope you found it informative. Feel free to leave comments, and ask questions.