Introduction to Binary Logic Circuits - by Nick Fletcher (2006)


home | page 1 | page 2 | page 3 | page 4 | page 5 | page 6
To construct the XOR GATE, we need to refer to the diagram above and translate that into C++ code...GROAN. Once we get this working, we'll be able to build our adding machine, then we'll leave gates for good. It's important to know about them, but it's essentially useless information. You will never work at such a low level. The transistors that make up these gates are microscopic and there are hundreds of millions of them inside most home computers. It's enough to know that the gates work, then, we can build on that knowledge without worrying about how they work. I already did that with the XOR above.
Going by the poor excuse for a schematic diagram, we can work out how to place our inputs/outputs and objects to simulate the circuit. We will need two NOT GATEs, two AND GATES and an OR GATE.
NOT not1("Not1"), not2("Not2");
AND and1("And1"), and2("And2");
OR or1("Or1");
The two AND GATEs receive their input from a NOTed input and a normal input. The output from this process is given to the lone OR GATE and it's this output that we want.
or1.ShowOutput(
               and1.ShowOutput(not1.ShowOutput(atoi(argv[1])),atoi(argv[2])),
                    and2.ShowOutput(not2.ShowOutput(atoi(argv[2])),atoi(argv[1])));
Wow! That's a MESS… But it should work! Here is the code:
      #include<iostream>
#include<string>

PROGRAM OUTPUT WHEN CALLED WITH - c:\???>gates3 1 0 <ENTER>

The inputs given are: 1 0
The XOR result is: 1

PROGRAM OUTPUT WHEN CALLED WITH - c:\???>gates3 1 1 <ENTER>

The inputs given are: 1 1
The XOR result is: 0

PROGRAM OUTPUT WHEN CALLED WITH - c:\???>gates3 0 1 <ENTER>

The inputs given are: 0 1
The XOR result is: 1

PROGRAM OUTPUT WHEN CALLED WITH - c:\???>gates3 0 0 <ENTER>

The inputs given are: 0 0
The XOR result is: 0
I commented out the cout in the objects to make the output clearer. And you can see that we are getting the exact results we are after. We can wrap the XOR GATE code and use it without worrying about how it works. I didn't mention it before, but there is a C/C++ bitwise operator that performs XOR operations. It's the '^' or carat.

We are ready to build our adding machine!


home | page 1 | page 2 | page 3 | page 4 | page 5 | page 6
nickeax AT gmail.com