Register Toffoli Method A Sandcastle Documented Class Library

Applies Toffoli gate. If all of the control bits are enabled, the target bit gets inverted. This gate with more than two control bits is not considered elementary and is not available on all physical realizations of a quantum computer. Toffoli gate with two control bits can be represented by unitary matrix:

Namespace: Quantum
Assembly: Quantum (in Quantum.dll) Version: (

public void Toffoli(
	int target,
	params int[] controls


Type: System Int32
The position of target qubit in register (0 indicates the Least Significant Bit).
Type:  System Int32 
The positions of control qubits in register (0 indicates the Least Significant Bit).

 namespace QuantumConsole
    public class QuantumTest
        public static void Main()
            QuantumComputer comp = QuantumComputer.GetInstance();

            Register x = comp.NewRegister(1, 3);

            Console.WriteLine("Register x: \n{0}", x);

            x.Toffoli(2, 0, 1);

            Console.WriteLine("Register x after Toffoli(2, 0, 1): \n{0}", x);

            Register y = comp.NewRegister(7, 4);

            Console.WriteLine("Register y: \n{0}", y);

            y.Toffoli(3, 0, 1, 2);

            Console.WriteLine("Register y after Toffoli(3, 0, 1, 2): \n{0}", y);        
See Also