Skip to content

Bitwise Invert

The bitwise inversion operation receives a quantum register representing some number \(x\), and inverts its binary representation, namely, replaces \(1\)s by \(0\)s and vice versa.

Example

from classiq import Output, QArray, QBit, QNum, create_model, prepare_int, qfunc


@qfunc
def main(x: Output[QNum], y: Output[QNum]) -> None:
    prepare_int(6, x)

    y |= ~x


qmod = create_model(main)
from classiq import execute, synthesize, write_qmod

write_qmod(qmod, "bitwise_invert_example")
qprog = synthesize(qmod)

result = execute(qprog).result()[0].value
print(result.counts_of_multiple_outputs(["x", "y"]))
{('011', '100'): 1000}