Here's something that will be new to some of you at least
Which in my opinion is the coolest logical operation in the world
It really, some of its properties are so nice you just go, "Wow, that's great."
It's exclusive Or.
Let's write down a truth table for this thing.
The exclusive or is like the inclusive or.
It comes out as true if either one of the inputs is a one.
but not when both of them are a one.
That's why it's called exclusive.
If they're both one, it doesn't come out as a 1 it comes out as a 0.
Another way to look at it is to say
the outcome's a 1 only if the two inputs differ.
If they're the same then the outcome's 0.
So here we go: 0 exclusive ored with a 0, they're the same, it's 0.
A 1 exclusive ored with a 1, they're the same so that's a 0.
But a 1 with a 0 or a 0 with a 1, they're different, so the answer is a 1.
And for this reason, the exclusive or operation
is sometimes called
a not equivalence operation
A NEC, as well as exclusive or.
But if we're writing this down again in our electronics engineer-type notation, how do they like to write it down
well this one's a special favourite of mine
it doesn't just have a go faster fast back to it.
it's got actually a double go faster aerodynamic fast back like that.
So you get your two inputs
a
b
you get your output here. Now how can you denote a exclusive ored with b?
Well, lots of ways.
Computer scientists would probably prefer to just write out xor.
Largely because many assembly languages will have an xor operation and that's the way you think about it.
But mathematical logicians may prefer
and we very often see this so be aware of it
to put a plus inside a circle.
Like that. And that's to denote that it's not the inclusive or
for which they'd use a plus sign on its own but it's a special form of plus.
If fact, as you'll see in just a minute it's precisely the form of addition you need for a binary adder circuit.
It really really is.
But don't forget, don't be thrown if you see it written particularly in old textbooks
some of them might call it the "not equivalence operation"
a not equivalence with b.
let me just show you now
what happens if I exclusive or
not just a single bit with a single bit
but suppose we're doing a 3-bit binary adder.
Dead simple.
Unsigned addition.
No two's complement. Nothing silly.
Just straightforward vanilla binary adder.
I'm going to write down 101.
Which you all know is 5.
I'm going to write down 010, which you all know is 2.
And I'm going to put between them
a circle plus
to show you I'm exclusive oring
Now what what happens from the right
1 exclusive ored with 0
They differ.
Therefore the outcome is a 1.
0 exclusive ored with 1, they differ
the outcome's a 1.
I've done this very carefully.
Left hand column 1 exclusive ored with 0 they still differ, that's 1.
5 and 2 is 7.
That's magic all you've done, it's binary adder.
To which my repost will be, "Yes it's a binary adder but I've carefully drawn a veil
over what would happen if I had to carry.
a bit from one position to the next."
Because that needs extra attention.
So think of it this way, the exclusive or is what you want for adding together all of the bits in a given column of a binary adder.
The only trouble is is it doesn't take care of the carrying out the bit to the next column on the left.
I can now show you the beginnings of how you could build
or draw a logic diagram for your favourite electronics person to build for you.
a 1-bit part binary adder
It's technically known, here, as a half adder.
So if you focus in on this, just look at this,
First of all I'm revising here up at the top
Here's what we've now done, we've done 'and', 'or', exclusive or and not
There's a rather better drawn, neater gate, up there
But just look at this
at the top you will now recognize an exclusive or gate.
with two inputs 'a' and 'b'.
The output of those is called the sum.
It's the sum in that column.
However if it so happens that a and b are both 1
we know what will happen with exclusive or
it will say, "oh, they're the same. So I generate a 0"
Wow! That's good. That's the right answer. You want to generate a 0, but you want to carry 1.
So how do you generate the so-called carry-out bit?
The answer is, in parallel with the inputs a and b going into the exclusive or
you take them in parallel to an 'and' gate.
Now remember, just want you're going to need, you're only going to carry if both of those bits in that column were 1.
1 and 1 is 0.
And that means you must carry out 1
to the position to the left.
The carry bit is the logical result of anding together a and b.
and I've given you the truth table over here on the right for the whole shebang.
Here's your a, here's your b
Here's what the carry bit must be
It must be a 1 only if the two inputs are 1s.
In the second column here's the sum.
A 1 if you're adding naught and one and zero,
if you're adding two zeros it's obviously a zero.
If you're adding two 1s it's a zero but you've taken care of the carry out.
You can see why that's called a half adder.
I mean we relax back, we have glass of champagne, a pint of beer, whatever turns you on, but you've only done half the job.
Because the hard bit is- and I can here lots of you in the comments already saying, "Ah, but what about carry in?!"
Here I am in the middle of a 32-bit binary addition, slack-bang in the middle and on column 15 I have to carry in
coming from my right, as well as having to give a carry out further over to the left.
Uh, yes! Well
For those of you who are hardcore, or haven't seen it before
let me just finish this little excursion by saying, "if you want to know what a full
1-bit adder has to look like"
just feast your eyes on this one here.
At the top left, that's the main exclusive or that does the straightforward addition of the digits that are in that column
that you're trying to add at the moment.
Down here at the bottom is the carry out
that we had before
but the complication now is
you've got to do the carry in.
How do you do the carry in?
Well you bring it in as C subscript in, it just comes in
the carry in to this position is what the carry out was from the previous position that you've just done
And you bring it in here.
And I want you to work your way through this and convince yourself that this is the right answer.
The carry in bit
Will affect the carry out bit
because as we saw when we were doing binary addition
You sometimes get a situation when there's a carry in of 1
but the two figures in the column to be added up also are 1s
So you can have 1 + 1 + 1, right?
Which is like 3, which is like
modulo 2 arithmetic, it's like a 2 to be carried but with a remain of 1.
So 1+1+1 is write down the 1 and carry the 1.
And this bit of the circuit down here
is the extended carry out circuit which copes with the fact that the carry in may have given you yet another 1
to be added in as well as the two 1s that were in the column already.
So here's the overall truth table
for everything folks.
Your a and b inputs in this particular column
Whether you have a carry in or not, was it naught or 1.
And in the light of all of those just read across and you'll find out what happens
If a and b are 0 and you have a 0 carry in, it's easy. There's no carry out and the sum of the two is 0.
Down here, the really hardest one of all
is if you've got an a and b of 1
and a carry in of 1
that's going to be 1 down and carry 1
so 1 and 1 at the bottom
intermediate, you can check through.
Everything checks out just the way it does.
So apart from all this are the charms which we've yet to discover
the great thing about exclusive or is that it's just what you need
with a few extra,
and gates and an or gate
to do the carry outs and carry in. If you do all that
exclusive or is at the heart of what a binary adder circuit has to have.
go-faster tail fin there
and it slips round like this
There is your 'or' gate with an 'a' and a 'b'.