https://export.arxiv.org/ftp/arxiv/papers/1908/1908.07943.pdf page 4 point 1 states that we use the bits of an integer as a basis in our space. I understand that BigEndian grabs our largest bit and creates a qubit. I am wondering if there is a function within Q# that does this for me.


I don't think there's a single function, but here's how you can do this with several library functions:

open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Diagnostics;

operation Demo () : Unit {
    let N = 12;
    Message($"Number: {N}");
    let bitsLE = IntAsBoolArray(N, 4);
    Message($"Bits in little endian: {bitsLE}");
    let bitsBE = Reversed(bitsLE);
    Message($"Bits in big endian: {bitsBE}");
    using (qs = Qubit[N]) {
        ApplyPauliFromBitString(PauliX, true, bitsBE, qs);
  • IntAsBoolArray converts an integer to a bit string with the given number of bits (in this case [False,False,True,True]).
  • Reversed returns the bits of the array in reverse order, i.e., converts them from little endian to big endian ([True,True,False,False]).
  • ApplyPauliFromBitString applies an X gate to each of the qubits that correspond to true elements of the bitsBE array ($|1100\rangle$).
  • $\begingroup$ what is the purpose of making sure that the true elements of bitsBE have an X gate applied? $\endgroup$
    – Mridul
    Jun 14 '20 at 23:15
  • $\begingroup$ Well, that's how you actually encode the state :-) Freshly allocated qubits start in the |0⟩ state, so to convert them to |1⟩ in positions which correspond to 1s in the binary notation, you apply X gate to those positions $\endgroup$ Jun 14 '20 at 23:32
  • $\begingroup$ Ok, I am looking to take one bit string and characterize it as qubit and do so for multiple bit strings in one quantum system. In that case, would this encoding produce redundant (non-basis) qubits? $\endgroup$
    – Mridul
    Jun 14 '20 at 23:36
  • $\begingroup$ This doesn't sound like the original question... Can you provide more details? An example maybe? $\endgroup$ Jun 14 '20 at 23:46
  • 1
    $\begingroup$ This looks more like docs.microsoft.com/en-us/qsharp/api/qsharp/…, though that one uses little endian. $\endgroup$ Jun 15 '20 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.