Commit 1b192c9c authored by MikJak75's avatar MikJak75
Browse files

half adder notebooks added

parent 7218353f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` 
```
+40 −0
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
from qiskit import *
from qiskit.tools.visualization import plot_bloch_multivector
from qiskit.tools.visualization import plot_histogram

# Creating a circuit with 3 quantum bits and 2 classical bits
qc = QuantumCircuit(3,2)

# Preparing inputs
qc.x(0) # Comment this line to make Qbit0 = |0>
qc.x(1) # Comment this line to make Qbit1 = |0>
# no changes to Qbit2 (stays |0> always)
qc.barrier()

# Applying AND operation and put result to Qbit2
qc.ccx(0,1,2)
qc.barrier()

# Applying XOR operation and put result to Qbit1
qc.cx(0,1)
qc.barrier()

# Reading outputs
qc.measure(1,0) # Reading XOR value ( sum bit )
qc.measure(2,1) # Reading AND value ( carry-out bit )

#qc.draw(output='mpl')

# Run the experimient 1024 times and get stats
counts = execute(qc,Aer.get_backend('qasm_simulator')).result().get_counts()
print(counts)

#credit: https://lahirumadushankablog.wordpress.com/2020/02/04/quantum-half-adder-and-full-adder/
```

%% Output

    {'10': 1024}
+0 −0

Empty file added.

test.ipynb

0 → 100644
+0 −0

Empty file added.