Basis States, Bitstrings, And Qubit Order
This chapter exists because many beginners lose hours to bit ordering.
The rule to remember
Qiskit uses little-endian ordering for basis states.
That means qubit 0 is the least significant bit in a computational-basis label.
For example, the label |10> means:
- qubit
1is1 - qubit
0is0
This feels backwards at first. You still need to internalize it.
A quick sanity check
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(2)
qc.x(1)
print(Statevector.from_instruction(qc))
This prepares |10>, not |01>.
Why this matters
All of these depend on qubit order:
- reading statevectors
- interpreting counts
- preparing a target basis state
- writing arithmetic circuits
- solving QCoder problems with explicit target strings
When a circuit looks almost right, ordering is one of the first things to check.
State labels and measurement strings
The same bit-ordering convention shows up in measurement output.
If you do:
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
qc = QuantumCircuit(2)
qc.x(0)
qc.measure_all()
sampler = StatevectorSampler()
result = sampler.run([qc], shots=16).result()
print(result[0].data.meas.get_counts())
the counts show "01", because qubit 1 is the left bit and qubit 0 is the right bit.
A debugging habit that pays off
Whenever you target a basis state, write down both:
- which qubits you are changing
- which basis label you expect to see
For example, if you want |101>, say it out loud:
- qubit
2should be1 - qubit
1should be0 - qubit
0should be1
That kind of explicitness prevents a large class of mistakes.
A small table worth memorizing
For two qubits:
|00>meansq1=0, q0=0|01>meansq1=0, q0=1|10>meansq1=1, q0=0|11>meansq1=1, q0=1
If this table feels natural, later arithmetic and QFT chapters become much easier.
Checkpoint Exercises
- Prepare
|10>on two qubits. - Prepare
|101>on three qubits. - Explain why
qc.x(0)on two qubits gives|01>. - Create a small table for all 2-qubit basis states and the qubit values they represent.