# Coding The Half Adder Quantum Circuit

Recently, I learned about half adder quantum circuits and decided to replicate one. In quantum computing, we use tools called quantum logic gates, which are quantum circuits that is operating on a small number of qubits. In this algorithm, we will use Qiskit to encode our input, perform our desired operations on each bit using logic gates, and extract our output! I will be adding 1+1 on a 4-qubit system.

# The Process

While using Jupyter Notebook, I begun by encoding the inputs.

`qc = QuantumCircuit(4,2)# inputs encoded in 0 and 1 qubitsqc.x(0) #1st qubit flipped to 1qc.x(1) #2nd qubit flipped to 1 in order to perform the addition 1+1`

Then, I used our CNOT gate to XOR input of qubit 2.

`# cnots used to write the XOR of the inputs on qubit 2qc.cx(0,2)qc.cx(1,2)`

Here, I extracted the outputs from this gate.

`# outputs extractedqc.measure(2,0) # extract XOR valueqc.measure(3,1)qc.draw(output='mpl')`

Addition of the ccx Tofolli gate.

`qc = QuantumCircuit(4,2)# inputs encoded in qubits 0 and 1qc.x(0) qc.x(1)# cnots used to write the XOR of the qubit 2 inputs qc.cx(0,2)qc.cx(1,2)# ccx is used to write the AND of the qubit 3 inputs qc.ccx(0,1,3)# outputs extractedqc.measure(2,0) # extract XOR valueqc.measure(3,1) # extract AND valueqc.draw(output='mpl')`

Finally, I ran the circuit on a quantum simulator.

`counts = execute(qc,Aer.get_backend('qasm_simulator')).result().get_counts()plot_histogram(counts)`