liveBook · Manning

Big-endian

As explained in Quantum Programming in Depth

Big-endian encoding orders a bit string or composite value with its most significant bit or component first.

Big-endian encoding maps a bit string to an integer with the most significant bit first and the least significant bit last. Thus, two-qubit state |01⟩ maps to 1 in big-endian notation, while the same written string maps to 2 in little-endian notation. The choice matters whenever basis states, state-vector amplitudes, measurement strings, or matrix rows and columns are indexed by integers. section 2.3 section 3.5.1

Endianness is a representation convention, not a universal quantum-computing rule. Q# uses big-endian notation for qubit-register interpretation, whereas Qiskit uses little-endian notation internally; Qiskit measurement output reverses the displayed order into a big-endian bit string. Name qubits by least- and most-significant roles rather than by left/right position to keep the mapping explicit. section 2.3 section 4.1.2

Use big-endian consistently when translating between representations:

  • Read a register as most-significant bit through least-significant bit when assigning integer meanings to basis states or amplitude-array positions. section 2.3
  • Account for row and column bit ordering before deriving a controlled-gate matrix, since the integer-to-basis-state mapping changes its block structure. section 3.5.1
  • Reverse a Q# qubit array when an API interprets an integer control pattern little-endian but the register convention is big-endian. section 3.9.3
  • Convert Qiskit measurement keys with standard binary parsing only after recognizing that their displayed order is big-endian. section 4.1.2

Reconciling a Q# control pattern

A Q# register stores its most significant qubit first, but ApplyControlledOnInt converts its integer argument into a little-endian control-pattern bit string. For a controlled operation using pattern k, reverse the relevant qubit slice before passing it as controls. This changes only the array-variable order, not the quantum state or applied gates. section 3.9.3

Listing 3.19 Q# code to implement an arbitrary CS unitary
import Std.Arrays.*;

operation ApplyArbitraryCSMatrix(
  qs : Qubit[], 
  cs : (Double, Double)[]   #1
) : Unit is Adj + Ctl {
  for (k, (c, s)) in Enumerated(cs) {
    let m = [[c, -s], [s, c]];
    ApplyControlledOnInt(k, ApplyOneQubit, 
      Reversed(qs[1...]), ([qs[0]], m));
  }
}

Inspect the reversed control-register slice used to reconcile Q# register ordering with ApplyControlledOnInt control-pattern ordering. section 3.9.3

Big-endian also labels phase-estimation output: with two control qubits, the first qubit stores the most significant estimated eigenphase bit before measurement. section 5.3.5

How Quantum Programming in Depth covers it

How deep it goes
Defines integer mapping and traces its implementation consequences for matrices, Q# controls, and Qiskit readout without deriving a general conversion algorithm.
Examples
Uses |01⟩ integer mappings, Q# reversed control arrays, deterministic Qiskit readout tests, and two-bit phase estimation.
What it assumes
Assumes familiarity with bit strings, basis states, and integer indices while refreshing their endianness mapping.
What you can do after
Diagnose/debug ordering mismatches by matching integer, bit-string, qubit-array, and measurement conventions.
How it connects
Connects basis states, state vectors, controlled gates, measurement results, Qiskit, Q#, and quantum phase estimation.

Also explained in

Compare how 2 books explain big-endian →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quantum Programming in Depth. The section links point to the parts of the book it draws on.