If you like the Educationaltechs contents, then also subscribe Educationaltechs youtube cahnnel to watch informational videos on YouTube Subscribe Now

Role Of Transistor, AND Gate, OR Gate, XOR Gate, Binary Numbers In Computers. How Do Computers Do Calculations?

Inside a computer, you'll find a motherboard, the motherboard acts as the chassis inside a car, giving all the components something to connect to. On the motherboard, there is the microprocessor, most microprocessors have some jagged metal on top called a Heat sink, to prevent overheating. If you remove the microprocessor and look underneath, you'll see a lot of wires sticking out that connect from the holes on the motherboard to the main part of the microprocessor. The microprocessor is made up of different areas that do different things such as adding or storing numbers. These areas are mostly made up of one thing, the transistor.

Transistor

The transistor's base is a semiconductor that sometimes conducts electricity and sometimes does not. The semiconductor has positively charged areas and negatively charged areas. Electricity will not flow between the two areas unless a conducting channel is opened up in the rest area. A conducting channel is opened up in the semiconductor when a conductor such as metal is placed above the gap wrapped in an insulator-like glass and electrified for electricity to flow through the conducting channel between the two areas.

There must be a source and a drain, in other words, an input and an output. These are both made from conductors as well, like metal. If the input is charged, it cannot flow to the output unless the gate which is the piece of metal in the middle is also charged. When the gate is charged it opens up the conducting channel in the semiconductor allowing electricity to flow down through the source, over to the other side of the semiconductor, and back up out the drain. The neat thing about this setup is that there are no moving parts and you are using electricity alone to turn on and off other electricity.

OR Gate

The breakthrough idea with this technology was using it to form logic gates. For instance, if you have two transistors and you add power to the inputs of each transistor and then add switches to each of the gates and allow the outputs to both flow directly to a light bulb you have created an OR gate. Turn any one switch on or even both switches on then the light bulb turns on.

And Gate

If you change the wiring so that the output wire of the first transistor runs to the input wire of the second transistor, then you've created an AND gate. With an AND gate if you only turn the first switch on then the light bulb is not on because the electricity coming from the first transistor is stopped at the second transistor. If you only turn the second switch on the light bulb is not on because there is no electricity flowing through the first transistor to reach the input of the second transistor so the light bulb does not turn on. So, both switches must be on in an AND gate for the output to be on as well.

Read Also: What Is RAM? Different Types Of RAM, Difference Between SRAM And DRAM.

Binary Numbers

On and off can be represented in the case of the switches as zero and one, if the switch is off then it represents zero, and if the switch is on it represents one. On the same with the light bulbs, if the bulb is off then it represents zero, and if the bulb is on it represents one. Zeroes and ones are the languages of computers and they make up their own numbering system called Binary Numbers.

Let's start counting in our normal decimal system and make a note of any binary numbers that we run across. In other words, any numbers that only have ones and zeros in them. So, to begin we record 0000 because it only has ones and zeros in it. Same with 0001 we have to wait to record another number in binary until we get to the number 0010, because 0002, 0003,.........,0009 do not work in binary. Then 0011 works, 0012 does not, 0013 does not, and 0014 does not, in fact, we can count by tens at this point because we won't see another number with only ones and zeros until we get to 0100. But, then 0101 works and then nothing again until 0110 and 0111 and we won't see all ones and zeros again until we get all the way up to 1000. Well, let's keep counting up to get all the numbers above 1000 in binary. So, 1001, 1010, 1011, 1100 1101, 1110, 1111.

Related Article: Parts Of Calculator. How Does Calculator Work?

Now we can spread them out and add light bulbs underneath them. If you have remembered from earlier we can represent binary numbers with light bulbs, which are 0 if the bulb is off and 1 if the bulb is on. So we start with 0000 or all light bulbs off, then move to 0001 where only the light bulb is on and then 0010 which is the same as the number 2 in decimal. Remember we only have 2 numbers to use in binary 1 and 0, this means that we have to count up a little differently than we do when we use decimal numbers. 0011 is 3 in decimal because it's the third binary number. 0100 is 4 and so on and on.

In fact,  let's make this easier when only one light bulb is on let's write the decimal number that it represents on the light bulb itself. For instance, 0001 in binary is 1 in decimal so we'll note that on that light bulb, 0010 in binary is 2 in decimal, 0100 in binary is 4 in decimal, and 1000 in binary is 8 in decimal. From here you just have to add up the numbers and the light bulbs that are lit, to find the equivalent number in decimal. So for instance 1001 is the 8 light bulb plus the 1 light bulb which means it's 9 in decimal, 1010 is the 8 light bulb plus the 2 light bulb which is 10 in decimal and finally, 1011 is the eight light bulb plus the 2 light bulb plus the 1 light bulb which is 11 in decimal. Now, 0001 plus 0001 in binary equals 0010 which is 2 in decimal.

Since switches can also represent ones and zeros, let's put two switches on the left and then an adding machine in the middle to see how we can do this with the logic gates we made earlier, this adding machine is called a Full adder because it's made up of two half adders. Now inside the half adder, it's easy to hook up the switches to the left light bulb, all we have to do is use an AND gate. Both switches then have to be on for the left light bulb to be on.

Related Article: How Does Touchscreen Work? How Does OLED Work?

Now to turn on the right light bulb we'll use an exclusive OR gate which is represented by the XOR. The exclusive OR gate acts just the way you would expect, either one switch or the other switch has to be on exclusively for the output to be on. If both switches are on or if both switches are off, the output will be off.

What Makes Up This Exclusive OR Gate?

It's an OR gate a NAND gate and an AND gate. Well, what's a NAND gate? That's just an AND gate with a NOT gate on the back end. A NOT gate just flips whatever the output is to its opposite. In other words, the NAND gate is only off if both inputs are on the exact opposite of the AND gate this is the key part of the exclusive OR gate.

Related Article: Smartphone Charger Components, Construction And How It Works?

How Does An Exclusive OR Gate Work?

When we turn just the top switch on, the OR output in the Exclusive OR gate is on and the NAND output is on, so the AND output is on as well, and therefore, the right light bulb is on. Now if we turn the top switch off and the bottom switch on we'll get the exact same output. If both switches are on though the exclusive OR gate is off, but the separate AND gate below it is on causing the left light bulb to be on. In other words, 0001 plus 0001 equals 0010.

Related Article: eMMC Storage, Its Benefits And Characteristics, eMMC VS SSD. FAQs

How Do Computers Do Calculations?

Now let's just focus on the full adder as a unit which we'll just call an Adder. Let's label the wires we'll use A and B to represent the input from our two switches and sum to represent the wire to the light bulb. Now let's remove the switches and connect seven more adders. Now we have eight adders next to each other and let's label them from right to left with letters (A, B, C, D, E, F, G, H) so that we can talk about them separately. We'll add two switches above each of our adders to represent our A and B inputs and then we'll connect a lightbulb to each of our sum outputs. The light bulbs again can be labeled with their decimal equivalents 1, 2, 4, 8, and then just keep multiplying by 2, we get 16, 32, 64, and 128.

Let's now add an area on the left to see what we're doing. First, put the binary numbers that our switches and light bulbs represent and then a plus sign to represent the adders, and then we'll add the equivalent numbers in decimal form. Finally, we'll put numbers on the adders themselves showing the current state of each wire coming into the adder and going out, 0 or 1 (off or on).

Now let's see what happens when we add 1 (00000001) plus 1(00000001) well in adder A the A and B  inputs are both 00000001 and the carry-in wire is off so it's 00000001 plus 00000001 which in binary equals 00000010 causing the carryout wire to be on and the sum wire to be off. So then on adder B, the A and B inputs are 0 but the carry-in input is 1, so the sum line on adder B is on causing a 2-light bulb to light up, so 1 plus 1 equals 2.  You'll begin to see a little bit more about how this works as we do some more examples.

Related Article: What Is CMOS Battery, BIOS? How Do These Work? How To Clear CMOS? How To Replace It? FAQs

Let's look at 2 (00000010) plus 2 (00000010), in adder A, none of the inputs are on in this case, so neither the sum nor the carry-out wire is on. Adder B though has inputs A and B on, so the carryout wire from adder B is on, which then becomes the carry-in wire to adder C causing the 4 light bulb to light up, showing that 2 plus 2 equals 4.

3 (00000011) plus 3 (00000011) causes adder A on for the right to carry out a 1 which then causes adder B  to have to add 1 plus 1 which in binary equals 00000011. So both the sum wire of adder B and the carryout wire of adder B are on, causing the light bulbs under adder B and under adder C - both to be on. So 3 plus 3 equals 6.

Let's look at a few more examples for you to consider on your own. If you'd like try ten plus ten. Now let's look at 15 plus 12 and finally, 219 plus 36 which adds up to the maximum of our light bulbs - 255.  Now, this kind of thing happens millions of times a second inside of the microprocessor that fits on the motherboard inside of your computer. So, now hope we could be able to make you understand how computers add numbers and do complex calculations in seconds.