Big-Endian vs Little-Endian Qubits
Every quantum toolkit stores the state vector as an ordered list of amplitudes. The question is: which basis state does index refer to? The answer depends on whether the framework uses a big-endian or little-endian qubit convention — and mixing them up is one of the most common sources of subtle bugs in quantum programming.
The two conventions
Consider a 2-qubit system with qubits labeled and . There are exactly four computational-basis states:
To turn a bit-string into an integer index we need an ordering rule.
Big-endian (MSB first): qubit 0 is the most significant bit (MSB). The index is
State (qubit 0 = 1, qubit 1 = 0) maps to index .
Little-endian (LSB first): qubit 0 is the least significant bit (LSB). The index is
State (qubit 0 = 1, qubit 1 = 0) now maps to index .
The same physical state, a different index. This platform uses big-endian: qubit 0 is always the most significant bit.
Encoding an integer
To encode a non-negative integer into an -qubit big-endian register, write in binary with exactly bits (padding with leading zeros if needed), then flip qubit with an gate whenever bit equals 1.
For and (binary ):
| Bit position | Value | Qubit | Gate | |---|---|---|---| | bit 2 (MSB) | 1 | qubit 0 | X | | bit 1 | 0 | qubit 1 | — | | bit 0 (LSB) | 1 | qubit 2 | X |
Applying to qubits 0 and 2 produces , index 5 in big-endian order.
Why it matters
A controlled gate applies to a specific (control, target) qubit pair. If you believe qubit 0 is the MSB but your tool treats it as the LSB, you will write the control and target on the wrong physical lines, computing a completely different unitary. The state vector will look plausible — it will be normalized — but the algorithm will silently produce wrong answers. Keeping the convention explicit is therefore not a stylistic choice: it is correctness.
Try it
Encode the integer 6 (binary ) in a 3-qubit big-endian register. Remember: qubit 0 is the MSB. The grader checks the full state vector, so you must target the right qubits.
After running, look at the state-vector tab: all amplitude should sit at index 6, confirming that is the only populated basis state.
Sign in on the full site to ask questions and join the discussion.