# No cloning theorem and exclusive-or (XOR) operator

According to IBM's website,

[...]where we would [classically] have done an assignment (x=y), we instead initialize the target (x=0) and use exclusive or (x^=y).

This sounds like x is a copy (clone) of y, however cloning is impossible in quantum mechanics. What's going on?

-
Continue reading to example 9. –  user2963 Oct 31 '12 at 21:10

This is a standard trick in quantum computing: to allow reversibility when computing some function $f$, you keep all the inputs and you encode the result in an initially "blank" qubit set initially to $|0\rangle$. What you're describing is the simplest case: one single input qubit, and $f$ equal to the identity function.
Thus, you want your gate to take the state $|0\rangle|0\rangle$ (where the first qubit is the input and the second is blank) to $|0\rangle|0\rangle$ (i.e. keep the first one and compute on the second one), and to take $|1\rangle|0\rangle$ into $|1\rangle|1\rangle$. As the IBM website points out, one can do this with a CNOT gate controlled on the first qubit.
The no-cloning theorem, however, is not broken. Consider what happens when you input some general state $|\psi\rangle=a|0\rangle+b|1\rangle$: by linearity, the output will be $$a|0\rangle|0\rangle+b|1\rangle|1\rangle.$$ This is an entangled state, and definitely not equal to the cloned state $|\psi\rangle|\psi\rangle$.