YTread Logo
YTread Logo

Learn how computers add numbers and build a 4 bit adder circuit

Apr 11, 2024
so if we want to add 28 plus 22 it's pretty simple 8 plus 2 is 10 so we put the zero here we take 1 1 plus 2 plus 2 is 5 is 15 okay it's pretty simple now if we want to do that with binary it actually works more or less the same way, so we align all of our columns, so 28 in binary is 1 1 1 0 0 22 is 1 0 1 1 0, so we convert it, align the columns, we just go column by column. column so 0 plus 0 is 0 0 plus 1 is 1 1 plus 1 in binary is 2 but we don't have a 2 in binary, so we write it as 1 0, so the same thing we did here with the 10 here Do the same, so we put a 0 here and carry a 1 and that's how we write a 2 here again.
learn how computers add numbers and build a 4 bit adder circuit
We have 1 plus 1 plus 0, which is 2, so we write it in binary again taking the 1 and putting. the 0 down here and finally 1 plus 1 plus 1 is 3 and in binary a 3 is 1 1 and here we end up with the binary representation of 50, so this same algorithm works on any basis to be great and so on now. If we want to

build

a

circuit

that does this for us, really just it's actually a lot easier, I think then, then regular arithmetic because you only need to know a couple of facts and this is all you need to know, so if Yes You can

build

a

circuit

that does all of this, then you can add a single column because you have a and B, which is just the first number in the second number, and then you could also have this one that somehow carries on from the previous one, so if you have all of that, then we should be able to add some

numbers

together, so let's think about how we would build a circuit that does this and one way to do this is to simply break it down. you know input and output, so we have inputs a and B and then we have these two outputs, which are the sum that you put here at the bottom and then the carry.
learn how computers add numbers and build a 4 bit adder circuit

More Interesting Facts About,

learn how computers add numbers and build a 4 bit adder circuit...

I'll call it the carry bit because you would carry that bit. We move on to the next column, so if we look at just the case here where we have two

numbers

that we're adding, so we haven't included something from a previous column and we look at just the number that we're putting in. Down here, actually, this looks a lot like exclusive, or right, because if a or B is a 1, then this last bit here is a 1, if a or b is a 1, but not both, so we can start to build this. So we can have an exclusive or gate here, this is how you draw an exclusive or and we have our a and our B coming in and then going out will be this here now, what about the second part, the carry part here? well, this is also pretty simple because it will always be 0 unless a and B are 1 and that's just a NAND gate, so I can have a NAND gate here and a gate and just take this same input a and B that we had here. take it to the door and and this will be this bit here that we could potentially carry over to the next column and so this is actually enough to add two numbers, this can cover all of these cases here because we have our a and our B enter our two inputs and we have our two outputs here, this is the first output and then this here is the second output.
learn how computers add numbers and build a 4 bit adder circuit
Now it gets a little more complicated if we have a carry coming from a previous column because it's not enough. so we can add two digits because as soon as we can with this one plus one, then we have to take a 1 to the next column and in the next column we have to deal with three numbers, so we're just going to add this. case where we have this carry which could be a 1, well in that case again, if we look at the last column here, it's actually the reverse case here, so really what we want to do is invert this output here whenever the The carry bit is set and a smart way to do it is with another XOR gate because when you XOR something with a 1, it will invert it, so if we have our carry coming in here, we send it to the which we put down here because what happened if this is a one, then you know that a0x or one is going to be 1 to 1 XOR 1 is a 0 to 1 XOR to 1 again is a 0 and then here we have a 0 a 1, so this will give us this last column now for this first column, which is the carry bit that we are the carry, you know we could put in the next column, we have these The cases are covered correctly because if a and B are a 1, then we get our 1 and we even have this case covered here because if a NB is a 1, then we have a 1 here too, but we don't have these 2 covered.
learn how computers add numbers and build a 4 bit adder circuit
There are cases here where a or B is a 1 and we have this carry and we What we can do is say well if we have the exclusive carry or A or B we already have that exclusive carry or a and B so if a or B is a 1 and we have the carry then we want this so we can actually just and a or b so this is this, you know, a or B we already have and the carry bit is set, so we get this. one here, so now we have this case, now we have these two cases covered by this output of this and the door.
Wow, we want to bring the carry bit in there as well and we have these two cases where it's 1 covered by this and the gate and So, really what we want to do is say that this bit will be 1 every time this condition or this condition is met, so we can use an or gate, so this is an or gate, this is a gate and, this is an XOR so you don't get confused here and then this is the carry and this is actually what's called a full

adder

because we have a and B, so we have two numbers that we are trying to add, potentially we have a carry from a previous issue and then we get a sum which is the number that we put here at the bottom plus we get a carry that is going to the next column and so with this kind of simple circuit if we build one of these circuits for each column we can add, you know, as big a number as we want, as long as we keep building, you know, as many of these circuits as we want, so, For example, I've put together this diagram here showing the same four-replicated circuit. times and in this case you have an A and a B coming in here and the carry that comes out goes to the carry in the next circuit, so it's like you know when you're doing the arithmetic here you have a 1 plus to 1 you have a carry, come in like input for the next sum and that carry goes in here along with a new a and a new B that will be a and B for this column for the second column and then you have something that comes out that would be the number down here and then you have that carry that goes to the next column plus the new a and the B for that column comes out and so on and so on here I have drawn four of them so we can add two 4 bit numbers but we could keep building more and more of these if we wanted so to build this we can use some pretty simple components because we have XOR gates and these chips here actually. implement XOR gates and here is the datasheet for them and as you can see from this datasheet basically each of these chips has four drawn here. one two three four five six seven eight XOR gates, so we have two of these chips, each one has four, we also needed some gates and so there is another chip that has gates, we need eight of those, so each of these chips has four and gates as you can see in the data sheet so we have those we also need some o gates here we only need four of those so there is another chip that has four or gates so we have that and then a couple more things we need.
I need a board to build this, so let's build this on this board here and for the inputs I have these little DIP switches and each of these has four little switches that will allow us to set the for a 0 to 1 to 2 and to 3 for the number that we want to add and then another one for B zero one two and three for the other number that doesn't add and finally a couple more things that we need are some type of outputs here, so we have our sums coming out here and I just have some little LEDs that will light up for each of these digits and I have five of them because there are four outputs plus the final carry, which is, you know, because if you're adding two 4-bit numbers, you could end up with a 5-bit output , so the last transport will have another LED for that and then I'll power it with some USB, this is just a standard USB Charger that I cut the end off and just pulled the red and black wires out of there and that will give us 5 volts, so I'm going to go ahead and start building this on top of this. little breadboard here and I'll start by gluing these things onto the breadboard.
Okay, at this point I have everything on the board and all the chips are on, so each of these chips has a VCC, which is the positive. voltage and then ground so each of them are connected for each of these chips it's all on the board so I'm going to go ahead and just connect the first of the

adder

s and we'll play with that first and then do the rest are you good? So I have the first stage of this connected. I think we'll see, we'll turn it on and see what happens, but this, so I'm using the one that uses the XOR gates on this chip two of the gates and on this chip and then the o gate is here, so we have some kind of wires running back and forth, I guess as I do the extra bits, I hope the wires get a little shorter so everything fits, but in any case, this is the sum of the first two bits here and this will be the carry , so let's plug the power in, so I'm going to plug this in here and see What's going on and that's not good?
Oh, I'm not done yet. Well, I think I'm done. I just have to run a couple extra connections here because the switches weren't fully wired. Now we add energy and everything is there. disabled because these first two bits are disabled and if I activate any of these, hopefully, yes, we will see 0 plus 1 equals 1, so this is a binary 0 1, so this is the answer if we disable this and activate the other. See again, 1 plus 0 also equals 1, that's good and if we turn them on we get 1 plus 1 equals 2, so it looks like this is working, so now I'm going to go ahead and just plug in.
In fact, I'm going to connect the all 3 remaining adders or the 3 remaining adders for the remaining 3 bits here, you're okay, so I just finished this, so let's see if it works. I've been testing it as I go, but I haven't tried everything. all together, but let's see how it works if we plug this in, we have zeros and 0s, so we have all zeros at the output, so let's see if we want to do some arithmetic here with this, let's imagine we want to. to add 10 plus 7 and get 17, so in binary this is 10, this is 7, so we would add 0 and 1, then we would get 1 and we add 1 and 1 and that's 2, so it's zero, we take a 1, 1 and 1 again is 2. so 0 carries a 1 101 again is 2 so that is a 1 0 in binary so this is what we would expect so let's go ahead and try it then 10 is 1 0 1 0 so we can do 1 0 1 0 and You see, the output is 1 0 1 0 because we are adding that to 0, so 10 plus 0 is 0, so so far everything is fine and then 7 we can do 0 1 1 1, so if we do 0 1 1 1 here we go. we get 1 0 0 0 1 1 0 0 0 1 so it seems to be working

If you have any copyright issue, please Contact