Computational Basis Encoding
Classical computers store numbers as strings of bits — 0s and 1s — and quantum computers do the same at the register level. Understanding how integers map to multi-qubit states is essential before you can write any algorithm that processes numerical data.
Binary representation
Every non-negative integer can be written uniquely in base 2:
where each . The -bit string is the binary representation of . For example,
Computational basis states
An -qubit register has a computational basis of states, , one for every non-negative integer that fits in bits. The state is the tensor product of the individual qubit states that spell out the binary digits of . With qubit 0 as the most significant bit:
where .
For a 3-qubit register the eight basis states are:
| Integer | Binary | State | |---------|--------|-------| | 0 | 000 | | | 1 | 001 | | | 2 | 010 | | | 3 | 011 | | | 4 | 100 | | | 5 | 101 | | | 6 | 110 | | | 7 | 111 | |
Encoding with X gates
Every qubit starts in . To encode an integer , apply an gate to each qubit whose corresponding bit in is 1. The gate flips (and ), so selectively applying it writes 1s in the right positions.
To encode in a 3-qubit register (qubit 0 = MSB):
- Qubit 0 gets (bit = 1).
- Qubit 1 stays untouched (bit = 0).
- Qubit 2 gets (bit = 1).
The resulting state is .
General recipe
Given an integer and a register of qubits (qubit 0 = MSB, qubit = LSB):
- Write in binary: .
- For each position where , call
c.x(i).
The register is then in the pure state with amplitude 1.
Try it
Encode the integer 5 into a 3-qubit register. The grader checks the full statevector, so the amplitude of must be 1 and all others must be 0.
After running, look at the statevector panel: the only non-zero amplitude should appear at index 5
(the binary string 101), confirming the register holds .
Sign in on the full site to ask questions and join the discussion.