this video is sponsored by brilliant transistors are very simple components they are basically electronic switches when we apply current to one of its terminals a transistor lets electricity pass through but how can this simple Behavior make computers possible in today's video we are going to learn how transistors can be used to achieve more complex tasks like doing math and even interpreting instructions hi friends my name is George and this is core dumped before we begin just a reminder that you can find me on social media and our Discord server where I'm available to answer your
questions and by the way I keep getting requests to use my own voice instead of using text to speech the reason I don't record myself is because I grew up in South America and I'm not a native English speaker so I hope you like modern family cuz once I start recording myself that's what it will sound like Anyway let's start a single transistor typically has three terminals a collector an emitter and a base in a circuit it can act as an insulator preventing electricity from flowing between the collector and emitter terminals but if we apply
a small current to the base terminal it acts as a conductor allowing electricity to flow essentially a transistor can be seen as a switch but instead of mechanical movement it operates by using electrical signals in this example circuit we are using a transistor to turn on and off an LED by utilizing the base terminal as an input and the emitter terminal as an output signal we can mimic the input signal with a switch and visually represent the output signal with the LED let's dub this a simple gate in a simple gate when the input is
zero the output is zero when the input is one the output is one now let's tweak things a bit here when the input is zero the LED is on due to the way it is arranged within the circuit but pay attention to this setting the input to one causes the LED to turn off indicating to us the output is a zero this setup is commonly referred to as an inverter or a not gate this may seem a bit confusing this video I found on Twitter is a perfect example of this effect and if you want
more details you can watch this video by Ben eer where he explains all this using real components we're not limited to just one transistor by using multiple transistors we can achieve more complex Behavior if two transistors are connected in series when both inputs are zero the output will be zero because both transistors act as insulators similarly if either input is zero the output will be zero the only way to obtain a one in the output is by having both transistors act as conductors which happens when both inputs are set to one this is where we
begin to apply a powerful concept called abstraction instead of focusing on the individual transistors in the circuit we can abstract this into a white box a box that consistently outputs a specific value based on two given inputs this is known as an and gate an and gate outputs a value of one if and only if both inputs are one otherwise the output will be zero if we connect the transistors in parallel when both transistors act as insulators electricity cannot flow but in this setup having any transistor acting as conductor is enough to allow electricity to
flow so in this arrangement to get an output of one is not strictly necessary to set both inputs to one once more we can abstract this circuit into a box known as an or gate an or gate outputs a value of zero if and only if both inputs are zero otherwise it outputs a value of one these circuits known as logic gates are so fundamental that instead of representing them with boxes each one is assigned a dedicated symbol notice that since inputs and outputs are electrical signals we can connect the output of one logic gate
to the input of another this allows us to combine logic gates to achieve even more complex behavior for example if we desire this particular Behavior we can combine logic G Gates accordingly to achieve it this is where we begin to see the power of abstractions while this setup is ultimately composed of transistors it's much simpler to understand what's happening by thinking in terms of logic gates this circuit is known as an xor gate and it is also very important in computer science so it has its own symbol and now that we understand what logic gates
are let's use them to create more use ful things let's start with adders adding binary numbers is actually quite simple in fact binary addition works just like decimal addition 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 and 1 + 1 = two however the value two cannot be represented with a single binary digit when this occurs we say the addition has overflowed meaning we require an additional bit to represent the value so what we're aiming for is a circuit that takes two input values and produces two outputs the
sum and the carry let's break down the sum but before a quick message from brilliant your learning process doesn't have to be synonymous with mindlessly scrolling through a PDF brilliant is designed to offer small lessons that you can engage with whenever you find the time making learning a little each day both enjoyable and convenient one of the best brilliant features is the interactive nature of their lessons which encourage critical thinking skills skills through problem solving activities for those aiming to enhance their problem solving abilities brilliant is an ideal platform it's latest course thinking in code
lays down the foundational principles of coding enabling you to adopt the mindset of a programmer and you can pick more advanced topics such as Python Programming and the mechanics of large language models all while engaging with small and fun interactive lessons you can get for free 30 days of brilliant premium and a lifetime 20% discount when subscribing by accessing brilliant.org dumped or by using the link in the description below and now back to the video let's break down the sum we require a circuit that outputs zero when both inputs are the same and one when
they differ does this sound familiar it's precisely what an exor gate accomplishes so we've already solved half of the puzzle for the carry output we need a circuit that outputs the value one only when both inputs are one this matches the behavior of and gate and there we have it we've crafted a circuit capable of adding two singled digigit binary numbers okay but what about multi-digit binary addition well let's try since we have to add numbers in each row using one Adder for each row seems logical it works well for the first row but when
we move to the second row there's an issue we need to consider that the previous row might have created a carry but because the adder circuit only accepts two inputs it doesn't account for this carry because of this limitation this circuit is known as a half adder and it is not useful in this scenario what we need is a full adder a circuit that can handle not only the two bits being added but also take into account the carry from a previous addition here's the circuit we're working towards think of it as a circuit capable
of adding three singled digigit binary numbers to simplify matters we can encapsulate this in a box which we'll call a full adder with full adders we can now add multi-digit binary numbers the carry output of each full adder feeds directly into the carry input of the next full adder as shown here in this animation to add binary numbers of n digits in one go n full adders are needed for example if we aim to add two 8 bit numbers we'll need eight full adders remember that values are represent Ed here using electrical signals since electricity
moves at incredible speed once we alter the input the output changes almost instantly and this is what makes transistors ideal for this job while logic gates can be crafted from other components like relays and even fancy 3D printed Parts powered by weird stuff like marbles or even water none of this matches the speed and compactness of transistors before Things become overly complex we can one more time package all of this functionality into a special component known as an 8bit Adder an 8bit Adder takes two 8-bit numbers as input and produces the sum of the inputs
as another 8bit number it also provides an overflow signal which is essentially the carry out output of the last full adder inside this overflow signal is crucial because it informs us whether the storage capacity being utilized is adequate to represent the result of the operation in this example both inputs are one bite long but if we attempt to store the output in just one bite we will miss information resulting in an incorrect value by monitoring the Overflow output we can recognize the need for an extra bite to accurately store the output believe it or not
neglecting to manage operation overflows can lead to undefined Behavior sometimes with severe consequences like this rocket accident in 1996 and we can continue to move to higher levels of abstraction if we want to make a circuit that increments an input value we can simply use an adder and set the second input to always be one we've only talked about adders in detail but in the end it's all about logic gates with them we can make more useful things like a full subtractor that then can be used to build an 8 bit subtractor and from there
we could keep going and make even more complicated stuff as you may have guessed inside the CPU there's a special component that houses all these circuits for now let's call it our mysterious component the question we want to answer now is when a CPU reads an instruction how does it identify which one of these circuits corresponds to that specific instruction how does the computer discern adding numbers upon encountering a particular instruction and subtract them upon encountering another I mean some instructions aren't even arithmetic operations the last type of component we are covering today are binary
decoders let's take a look at this circuit and examine the output for every input combination the first thing we can notice here is that each combination triggers a specific output to activate while deactivating all other outputs another way to see it is that the circuit receives the binary number that corresponds to the position of the output we wish to activate this is what binary decoders do when it receives an input one and only one output has the value of one with all others outputting the value of zero if we have a decoder with three inputs
we can control which of eight outputs turns on four inputs well we can control 16 outputs and so on this is huge because it means that we are also capable of creating circuits that can select among multiple options now remember that assembly code is just a humanfriendly representation of machine code the actual code consisting of ones and zeros that computers comprehend not all instructions are arithmetic operations some of them are instructions dedicated to fetch and write data to memory and other stuff like that let's imagine a very basic architecture where if the first two bits
of an instruction are zeros the computer interprets them as arithmetic operation instructions in this example to verify this we could employ nor Gates given the scope of this video at the moment we are not concerned with instruction that signifies something else but at least we know how to identify between them in this example architecture the third and fourth bits will determine the type of arithmetic operation to be executed for instance if those bits are 0 0 it means addition if 01 it represents subtraction and so forth this is commonly known as an OP code each
op code is associated with one and only one kind of arithmetic operation when the CPU has determined that the current instruction is an arithmetic operation Our Mysterious component receives this op code and internally links those two bits to a decoder which is used to identify the desired internal operation the straightforward approach here would be by allowing all circuits to receive the inputs and generate their respective outputs but the outputs of the decoder are interconnected in a way that allows only the output of the selected operation to pass through this component keep in mind that there
are more efficient ways to do this but here we focus on Simplicity Our Mysterious component can also be enclosed with within a box this is a rudimentary and somewhat incomplete version of something known as an arithmetic logic unit we'll talk about this component in more detail in a future episode where we discuss how CPUs execute instructions but beforehand an arithmetic logic unit takes input values and an OP code that tells the internal circuitry what arithmetic operation to perform between those values it then produces the result of the specified operation along with additional information such as
whether the result is negative 0 or if it has overflowed and this was a very very very brief introduction to how computers use transistors to do math and follow instructions well sort of because we completely avoided an important concept memory but that's a topic for a future video so make sure to subscribe because you don't want to miss it and that's it for this episode don't forget to hit that like button if you enjoyed this video or learned something it's free and that would help me a lot