Classical Logic Gates with Quantum Circuits
Using the NOT gate (expressed as x in Qiskit), the CNOT gate (expressed as cx in Qiskit) and the Toffoli gate (expressed as ccx in Qiskit) create functions to implement the XOR, AND, NAND and OR gates.
An implementation of the NOT gate is provided as an example.
NOT gate
This function takes a binary string input ('0' or '1') and returns the opposite binary output'.
XOR gate
Takes two binary strings as input and gives one as output.
The output is '0' when the inputs are equal and '1' otherwise.
AND gate
Takes two binary strings as input and gives one as output.
The output is '1' only when both the inputs are '1'.
NAND gate
Takes two binary strings as input and gives one as output.
The output is '0' only when both the inputs are '1'.
OR gate
Takes two binary strings as input and gives one as output.
The output is '1' if either input is '1'.
Tests
The following code runs the functions above for all possible inputs, so that you can check whether they work.