Bitwise Xor¶
The Bitwise Xor (denoted as '^') is implemented by applying this truth table between each pair of qubits (or qubit and bit) in registers A and B.
a | b | a ^ b |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Note that integer and fixed-point numbers are represented in a two-complement method during function evaluation. The binary number is extended in the case of a register size mismatch.
For example, the positive signed number \((110)_2=6\) is expressed as \((00110)_2\) when operating with a five-qubit register. Similarly, the negative signed number \((110)_2=-2\) is expressed as \((11110)_2\).
Examples:
5 ^ 3 = 6 since 101 ^ 011 = 110
5 ^ -3 = -8 since 0101 ^ 1101 = 1000
-5 ^ -3 = 6 since 1011 ^ 1101 = 0110
Syntax¶
Function: BitwiseXor
Parameters:
left_arg: Union[int, RegisterUserInput]
(see RegisterUserInput)right_arg: Union[int, RegisterUserInput]
(see RegisterUserInput)output_size: Optional[PositiveInt]
inplace_arg: Optional[str] = None
Register names:
left_arg
:left_arg
right_arg
:right_arg
result
:bitwise_xor
{
"function": "BitwiseXor",
"function_params": {
"left_arg": 3,
"right_arg": { "size": 3 }
}
}
Example 1: Two Registers¶
{
"functions": [
{
"name": "main",
"body": [
{
"function": "BitwiseXor",
"function_params": {
"left_arg": {
"size": 5,
"is_signed": true
},
"right_arg": {
"size": 3
}
}
}
]
}
]
}
from classiq import Model, QUInt, QSInt, synthesize
from classiq.builtin_functions import BitwiseXor
params = BitwiseXor(
left_arg=QSInt(size=5).to_register_user_input(),
right_arg=QUInt(size=3).to_register_user_input(),
)
model = Model()
model.BitwiseXor(params)
quantum_program = synthesize(model.get_model())
This example generates a circuit that performs bitwise 'xor' between two registers. The left arg is a signed register with five qubits and the right arg is an unsigned register with three qubits.
Example 2: Integer and Register¶
{
"functions": [
{
"name": "main",
"body": [
{
"function": "BitwiseXor",
"function_params": {
"left_arg": 3,
"right_arg": {
"size": 3
}
}
}
]
}
]
}
from classiq import Model, RegisterUserInput, synthesize
from classiq.builtin_functions import BitwiseXor
params = BitwiseXor(left_arg=3, right_arg=RegisterUserInput(size=3))
model = Model()
model.BitwiseXor(params)
quantum_program = synthesize(model.get_model())
This example generates a circuit that performs a bitwise 'and' between a quantum register and an integer. The left arg is an integer equal to three and the right arg is an unsigned quantum register with three qubits.