# Can we add two classical registers in IBM Quantum Experience?

Suppose I have 01 and 11 in classical register 1 and 2 respectively in IBM quantum experience circuit. I want 01 + 11 = 00 mod 4. Can it be done?

You can add two qubits firstly in quantum registers and then measure qubit with results and put it to classical register.

Adding two qubits modulo 4 can be do with this circuit: First $$CNOT$$ is fan-out and make a "copy" of qubit $$q_0$$ to $$q_2$$, second $$CNOT$$ realizes XOR function between $$q_1$$ and $$q_2$$. Eventually you have $$(q_0 + q_1) \mod 4$$ in $$q_2$$

EDIT: Expanded for two qubits adder modulo 4, based on comment by Adam Levine:

Here is a code implementing a modulo 4 adder for two qubits:

OPENQASM 2.0;
include "qelib1.inc";

qreg q;
creg c;

//first input qq
//second input qq
//output qq

//input
//qq = 01
id q;
x q;
//qq = 11
x q;
x q;

//first qubit:
//q + q - sum
cx q,q;
cx q,q;
//q, q - carry
ccx q, q, q;

//second qubit:
//q + q - sum
cx q,q;
cx q,q;
//no carry, modulo 4 sum


$$I$$ and $$X$$ gates set an input (based on the comment), $$CNOT$$ gates acting on qubit $$q_5$$ return sum of last (lower) qubits of input numbers. Toffoli gate is used for calculation of carry form last qubits and next two $$CNOT$$ gates add together the carry and first (higher) qubits of input numbers. Carry from this sum is not performed as the adder is modulo 4. The result is in qubits $$q_4$$ and $$q_5$$ where higher qubit is $$q_4$$ and lower $$q_5$$.

Note: this is based on classical approach how to construct an adder. There is also quantum approach based on quantum Fourier transform. See details here: Addition on a Quantum Computer

• Can I have a circuit for adding 2 qubits: 01 + 11 = 00 mod 4? Feb 24 '20 at 6:32