so if we want to add 28 plus 22 it's
pretty simple 8 plus 2 is 10 so we put
the zero down here carry the 1 1 plus 2
plus 2 is 5 it's 15 okay simple enough
now if we want to do that with binary it
actually works pretty much the same way
so we we line up all of our columns and
so 28 in binary is 1 1 1 0 0 22 is 1 0 1
1 0 so we've got that converted we line
up the columns we just go column by
column so 0 plus 0 is 0 0 plus 1 is 1 1
plus 1 in binary is is 2 but we don't
have a 2 in binary so it's we write it
as 1 0 so the same thing we did here
with the 10 here we do it the same thing
so we put a 0 down here and carry a 1
and that's how we write a 2 here again
we've got 1 plus 1 plus 0 which is 2 so
we write that in binary again by
carrying the 1 and putting the 0 down
here and then finally 1 plus 1 plus 1 is
3 and in binary a 3 is 1 1 and here we
we end up with the binary representation
of 50 so this the same algorithm works
in any base to kind of cool and so now
if we want to build a you know a circuit
that does this for us really there's
only it's actually a lot easier I think
then then regular arithmetic because you
only need to know a couple facts and
this is everything you need to know and
so if you can build a circuit that does
all of this then you can add a single
column because you've got the a and B
which is the just the first number in
the second number and then you might
also have this this one that sort of
carries in from the previous so if
you've got all that then then we should
be able to to add some numbers so let's
think about how we would build a circuit
that it kind of does this and one way to
do it is just kind of break down you
know input and output so we have the
inputs a and B and then we have these
two outputs which are the sum that you
put down here at the bottom and then the
carry I'll call this the carry bit
because you would carry that bit over to
the next column so if we look just at
the case here where we've got two
numbers that we're adding so we haven't
carried something in from a previous
column
and we look just at the number that
we're putting down at the bottom here
this actually looks a lot like in
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
actually start to build this right 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
coming out is going to be this right
here now what about the the second bit
the carry bit here well this is also
pretty simple because it's always going
to be 0 unless a and B are 1 and so
that's just a NAND gate so I can have a
NAND gate here and gate and just take
this same a and B input that we had over
here bring it into the and gate and this
will be this this bit here that we would
potentially carry over into the next
column and so this actually is enough to
add two numbers this can this covers all
of these cases here because we have our
a and our B input our two inputs and we
have our two outputs here this is the
this first output and then this here is
the the second output it gets a little
bit more complicated now if we have a
carry coming in from a previous column
because it's not enough to just be able
to add to two digits because as soon as
we could to this one plus one then we
have to carry a 1 to the next column and
in the next column we have to deal with
three numbers so let's just going to add
this case where we have this carry that
might be a 1 well in that case again if
we look at the last column here it's
it's actually the inverse of the case
here so really what we want to do is we
want to invert this output here whenever
the carry bit is set and a clever way of
doing that is with another XOR gate
because when you XOR something with a 1
it has it will invert it so if we have
our carry coming in here we send that
into the XOR gate and this will be the
sum that we put at the bottom here
because what happened
if this is a one then you know a0x or
one is going to be 1 a 1 XOR 1 is a 0 a
1 XOR a 1 again is a 0 and then here we
have a 0 X or a 1 is a 1 so this this
will will give us this this last column
now for this this first column which is
the carry bit that we are the carry you
know that we might put into the next
column we've got these cases covered
right because if a and B is a 1 then we
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 as well but we don't
have covered is these 2 cases here where
a or B is a 1 and we have this carry and
so what we can do is we can actually say
well if we have the carry exclusive or A
or B we have we already have that
exclusive or a and B so if a or B is a 1
and we have the carry then we want this
one so we can actually just and the a or
b so this is this is this this you know
a or B we already have and the carry bit
is set then we get this one here so now
we have this case now we have this these
two cases covered by this output of this
and gate
oops 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
gate and so really what we want to do is
we want to say that this bit is going to
be a 1 either time this condition or
this condition is met so we can use an
or gate so this is an or gate this is an
and gate this is an XOR so you guys
don't get confused here and then this is
the carry and so this actually is what
is called a full adder because we have a
and B so we have two numbers that we're
trying to add we potentially have a
carry from a previous edition and then
we get a sum out which is the the number
we put here at the bottom plus we get a
carry that goes into next column and so
with this sort of simple circuit
if we build one of these circuits for
each column we can add you know as large
a number as we like as long as we keep
building you know as many of these
circuits as we like and so for example
I've drawn up this diagram here which
shows that same circuit sort of
replicated four times and in this case
you have an A and a B coming in here and
the carry coming out goes into the carry
of the next circuit so this is sort of
like you know when you're actually doing
the arithmetic here you have a 1 plus a
1 you have a carry it goes in as an
input to the next addition and so that
carry comes into here along with a new a
and a new B which is going to be the a
and B for this column for the second
column and then you have a something
coming out which would be the number
down here and then you have that carry
going over which goes into the next
column plus the new a and the B for that
column carry comes out and so forth and
so here I've drawn four of them so we
can add two 4 bit numbers but we we
could keep building more and more of
these if we wanted to so to actually
build this we can use some some pretty
simple components because we have XOR
gates and these these chips here
actually implement XOR gates and here is
the datasheet for them and so you can
see from this datasheet basically each
of these chips has four XOR gates built
onto it and so you know to build a 4-bit
adder like I've drawn out here you need
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
and gates and so there's another chip
that has and gates we need eight of
those and so each of these chips has
four and gates as you can see on the
datasheet so we got those we also need
some or gates here we just need four of
those so there's another chip that has
four or gates so we got that and then a
couple other things that we that we need
we need a breadboard to build this on so
we're going to build this on this
breadboard here and for the inputs I
have these little little dip switches
and so each of these has four little
switches on it and that will let us set
the
for a 0 a 1 a 2 and a 3 for the one
number that we want to add and then
another one for the B zero one two and
three for the other number that won't
add together and then finally a couple
other things we need are some kind of
outputs here so we have our our sums
coming out here and so I just have some
little LEDs that will light up for each
of these digits and I have five of them
because there's four outputs plus the
final carry which is you know because if
you're adding two 4 bit numbers you
might end up with a 5 bit output so that
last carry will will have another LED
for that and then I'm just going to
power it with a little bit of a little
USB this is just a standard USB charger
that I've kind of hacked the end off of
and just taking the red and black wires
out of there and that will give us 5
volts so I'm going to go ahead and start
getting this thing built on this on this
little breadboard here and I'll just
start by sticking this stuff on to the
onto the breadboard
okay at this point I've got everything
on the board
and all the chips are powered so each of
these chips has a VCC which is the the
positive voltage and then the ground so
that each of those is connected for each
of these chips everything's on the board
so I'll go ahead and just actually just
wire up the first of the adders and we
play with that one first and then we'll
do the rest
you
okay so I've got the first stage of this
wired up I think we'll see we'll power
it up and see what happens but this so
I'm using the one of the using to the
XOR gates on this chip two of the and
gates on this chip and then the or gate
is over here so we have some kind of
wires running back and forth that I
guess as I as I do the additional bits
hopefully the wires I get a little
shorter so it all it all fit but any
event this these this is the the sum of
the first two bits over here and this
will be the carry so let's get the power
of n already plugged in so I'm going to
just hook this up here and see what
happens and that's not good oh I'm not
done yet
okay now I think I'm done I just have to
hook up a couple extra connections here
because the switches weren't fully wired
in okay so now we add power and
everything is off because these first
two bits are off and if I toggle either
of these on hopefully yes we see 0 plus
1 equals 1 so this is a binary 0 1 so
this is the answer there if we turn this
off and turn the other one on we see
again 1 plus 0 also equals 1 that's good
and if we turn both of them on we get 1
plus 1 equals 2 so it looks like this is
working so now I'll go ahead and just
wire up I'll actually wire up the all of
the remaining 3 adders or the remaining
3 adders for the remaining 3 bits here
you
okay so I just finished this so let's
see if it works I've been testing it as
I as I go but I haven't tested the whole
thing all together but let's let's see
how it does
if we plug this in we've got zeroes and
0 so we've got all zeroes on the output
there so let's see if we want to do some
some arithmetic here with this let's
imagine we want to add 10 plus 7 and get
17
so in binary this is 10 this is 7 so we
would add 0 & 1 then we get 1 and we add
1 & 1
and that's 2 so it's a zero carry a 1 1
and 1 again is 2 so 0 carry a 1 101
again is is 2 so that's a 1 0 in binary
so this is what we would expect so let's
go ahead and give it a try so 10 is 1 0
1 0 so we can do 1 0 1 0 and already you
see the output is 1 0 1 0 because we're
adding that to 0 so 10 plus 0 is 0 so
that's so far so good and then 7 we can
do 0 1 1 1 so if we do 0 1 1 1 there we
go we get 1 0 0 0 1 1 0 0 0 1 so it
looks like it's working