> ## Documentation Index
> Fetch the complete documentation index at: https://docs.classiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Bitwise Or

> [card] [View on GitHub](https://github.com/Classiq/classiq-library/blob/main/functions/function_usage_examples/arithmetic/bitwise_or/bitwise_or_example.ipynb)
>
> Open this notebook in GitHub to run it yourself

The Bitwise Or (denoted as '|') is implemented by applying the following truth table between each pair of qubits (or qubit and bit) in variables A and B.

\| a | b | a or b | | :-: | :-: | :----: | | 0 | 0 | 0 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 1 |

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 variable size mismatch.

For example, the positive signed number $(110)_2=6$ is expressed as $(00110)_2$ when operating with a five-qubit variable.
Similarly, the negative signed number $(110)_2=-2$ is expressed as $(11110)_2$.

Examples:

5 | 3 = 7 since 101 | 011 = 111

5 | -3 = -3 since 0101 | 1101 = 1101

-5 | -3 = -1 since 1011 | 1101 = 1111

## Examples

#

## Example 1: Two Quantum Variables

This example generates a quantum program that performs bitwise 'or' between two variables.

The left arg is a signed with five qubits and the right arg is unsigned with three qubits.

```python theme={null}
from classiq import *


@qfunc
def main(a: Output[QNum], b: Output[QNum], res: Output[QNum]) -> None:
    allocate(5, True, 0, a)
    allocate(3, False, 0, b)
    a ^= 4
    b ^= 5
    res |= a | b
```

```python theme={null}

qprog = synthesize(main)

result = sample(qprog)
print(result)
```

> [!NOTE]
>
> **Output:**
>
> ```
>
> Exception in callback Task.__step()
>   handle: <Handle Task.__step()>
>   Traceback (most recent call last):
>     File "/Users/alexandrecesarricardo/.pyenv/versions/3.11.15/lib/python3.11/asyncio/events.py", line 84, in _run
>       self._context.run(self._callback, *self._args)
>   RuntimeError: cannot enter context: <_contextvars.
>
> Context object at 0x10a0a8200> is already entered
>   Submitting job to simulator
>   Task was destroyed but it is pending!
>   task: <Task pending name='Task-6' coro=<_async_in_context.<locals>.run_in_context() done, defined at /Users/alexandrecesarricardo/classiq-library-new/classiq-library/venv/lib/python3.11/site-packages/ipykernel/utils.py:57> wait_for=<Task pending name='Task-7' coro=<Kernel.shell_main() running at /Users/alexandrecesarricardo/classiq-library-new/classiq-library/venv/lib/python3.11/site-packages/ipykernel/kernelbase.py:597> cb=[Task.__wakeup()]> cb=[ZMQStream._run_callback.<locals>._log_error() at /Users/alexandrecesarricardo/classiq-library-new/classiq-library/venv/lib/python3.11/site-packages/zmq/eventloop/zmqstream.py:563]>
>   /Users/alexandrecesarricardo/classiq-library-new/classiq-library/venv/lib/python3.11/site-packages/httpx/_models.py:248: RuntimeWarning: coroutine 'Kernel.shell_main' was never awaited
>     return self[key]
>   Task was destroyed but it is pending!
>   task: <Task pending name='Task-7' coro=<Kernel.shell_main() running at /Users/alexandrecesarricardo/classiq-library-new/classiq-library/venv/lib/python3.11/site-packages/ipykernel/kernelbase.py:597> cb=[Task.__wakeup()]>
>   Job: https://platform.classiq.io/jobs/661cbfd1-2f91-4173-b010-0c55453245d5
>
>
> ```

> [!NOTE]
>
> **Output:**
>
> ```
> a  b  res  counts  probability      bitstring
>   0  4  5    5    2048          1.0  0010110100100
>
>
> ```

#

## Example 2: Integer and Quantum Variable

This example generates a quantum program that performs a bitwise 'or' between a quantum variable and an integer.

The left arg is an integer equal to three
and the right arg is an unsigned quantum variable with three qubits.

```python theme={null}
@qfunc
def main(a: Output[QNum], res: Output[QNum]) -> None:
    a |= 4
    res |= 3 | a
```

```python theme={null}

qprog = synthesize(main)

result = sample(qprog)
result
```

> [!NOTE]
>
> **Output:**
>
> ```
>
> Submitting job to simulator
>   Job: https://platform.classiq.io/jobs/207d37b8-c0be-406f-920c-1b2391ed4c17
>
>
> ```

| | a | res | counts | probability | bitstring |
| - | - | - | - | - | - |
| 0 | 4 | 7 | 2048 | 1.0 | 111100 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.