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

# Encodings

Functions:

| Name                        | Description                                                                    |
| --------------------------- | ------------------------------------------------------------------------------ |
| `binary_to_one_hot`         | Conversion of binary encoded value to one-hot encoding.                        |
| `binary_to_unary`           | Conversion of binary encoded value to unary encoding.                          |
| `one_hot_to_unary`          | Conversion of one-hot encoded value to unary encoding.                         |
| `one_hot_to_binary`         | Conversion of one-hot encoded value to binary encoding.                        |
| `unary_to_one_hot`          | Conversion of unary encoded value to one-hot encoding.                         |
| `unary_to_binary`           | Conversion of unary encoded value to binary encoding.                          |
| `inplace_binary_to_one_hot` | Inplace conversion of binary encoded value to one-hot encoding.                |
| `inplace_one_hot_to_unary`  | Inplace conversion of one-hot encoded value to unary encoding.                 |
| `pad_zeros`                 | Pad the input qvar with additional qubits at the end to reach the total\_size. |

### binary\_to\_one\_hot

<pre><code>binary\_to\_one\_hot(
binary: Input\[QNum],
one\_hot: Output\[QArray]
) -> None</code></pre>

Conversion of binary encoded value to one-hot encoding. The output `one_hot` variable
is of size 2^n, where n is the number of bits in the binary representation.
For example, the state `|01>`=`|2>` will be converted to `|0010>` (one-hot for 2).

**Parameters:**

| Name      | Type             | Description                                                | Default    |
| --------- | ---------------- | ---------------------------------------------------------- | ---------- |
| `binary`  | `Input[QNum]`    | binary input variable to be converted to one-hot encoding. | *required* |
| `one_hot` | `Output[QArray]` | one-hot output array.                                      | *required* |

### binary\_to\_unary

<pre><code>binary\_to\_unary(
binary: Input\[QNum],
unary: Output\[QArray]
) -> None</code></pre>

Conversion of binary encoded value to unary encoding. The output `unary` variable
is of size 2^n - 1, where n is the number of bits in the binary representation.
For example, the state `|01>`=`|2>` will be converted to `|110>` (unary for 2).

**Parameters:**

| Name     | Type             | Description                                              | Default    |
| -------- | ---------------- | -------------------------------------------------------- | ---------- |
| `binary` | `Input[QNum]`    | binary input variable to be converted to unary encoding. | *required* |
| `unary`  | `Output[QArray]` | unary output array.                                      | *required* |

### one\_hot\_to\_unary

<pre><code>one\_hot\_to\_unary(
one\_hot: Input\[QArray],
unary: Output\[QArray]
) -> None</code></pre>

Conversion of one-hot encoded value to unary encoding. The output `unary` variable
is smaller in 1 qubit than the input `one_hot` variable.
For example, the state `|0010>` (one-hot for 2) will be converted to `|110>` (unary for 2).

**Parameters:**

| Name      | Type             | Description                                            | Default    |
| --------- | ---------------- | ------------------------------------------------------ | ---------- |
| `one_hot` | `Input[QArray]`  | one-hot input array to be converted to unary encoding. | *required* |
| `unary`   | `Output[QArray]` | unary output array.                                    | *required* |

### one\_hot\_to\_binary

<pre><code>one\_hot\_to\_binary(
one\_hot: Input\[QArray],
binary: Output\[QNum\[Literal\['ceiling(log(one\_hot.len, 2))']]]
) -> None</code></pre>

Conversion of one-hot encoded value to binary encoding. The output `binary` variable
is of size log2(one\_hot.size) rounded up.
For example, the state `|0010>` (one-hot for 2) will be converted to `|01>`=`|2>`.

**Parameters:**

| Name      | Type                                                    | Description                                             | Default    |
| --------- | ------------------------------------------------------- | ------------------------------------------------------- | ---------- |
| `one_hot` | `Input[QArray]`                                         | one-hot input array to be converted to binary encoding. | *required* |
| `binary`  | `Output[QNum[Literal['ceiling(log(one_hot.len, 2))']]]` | binary output variable.                                 | *required* |

### unary\_to\_one\_hot

<pre><code>unary\_to\_one\_hot(
unary: Input\[QArray],
one\_hot: Output\[QArray]
) -> None</code></pre>

Conversion of unary encoded value to one-hot encoding. The output `one_hot` variable
is larger in 1 qubit than the input `unary` variable.
For example, the state `|110>` (unary for 2) will be converted to `|0010>` (one-hot for 2).

**Parameters:**

| Name      | Type             | Description                                            | Default    |
| --------- | ---------------- | ------------------------------------------------------ | ---------- |
| `unary`   | `Input[QArray]`  | unary input array to be converted to one-hot encoding. | *required* |
| `one_hot` | `Output[QArray]` | one-hot output array.                                  | *required* |

### unary\_to\_binary

<pre><code>unary\_to\_binary(
unary: Input\[QArray],
binary: Output\[QNum]
) -> None</code></pre>

Conversion of unary encoded value to binary encoding.  The output `binary` variable
is of size log2(unary.size + 1) rounded up.
For example, the state `|110>` (unary for 2) will be converted to `|01>`=`|2>`.

**Parameters:**

| Name     | Type            | Description                                           | Default    |
| -------- | --------------- | ----------------------------------------------------- | ---------- |
| `unary`  | `Input[QArray]` | unary input array to be converted to binary encoding. | *required* |
| `binary` | `Output[QNum]`  | binary output variable.                               | *required* |

### inplace\_binary\_to\_one\_hot

<pre><code>inplace\_binary\_to\_one\_hot(
qvar: QArray
) -> None</code></pre>

Inplace conversion of binary encoded value to one-hot encoding.
The implementation is based on [https://quantumcomputing.stackexchange.com/questions/5526/garbage-free-reversible-binary-to-unary-decoder-construction](https://quantumcomputing.stackexchange.com/questions/5526/garbage-free-reversible-binary-to-unary-decoder-construction).
The input is assumed to be of size 2^n, where n is the number of bits in the binary representation.
For example, the state `|01000>`=`|2>` will be converted to `|00100>` (one-hot for 2).

**Parameters:**

| Name   | Type     | Description                                                             | Default    |
| ------ | -------- | ----------------------------------------------------------------------- | ---------- |
| `qvar` | `QArray` | binary input array padded with 0's to be converted to one-hot encoding. | *required* |

### inplace\_one\_hot\_to\_unary

<pre><code>inplace\_one\_hot\_to\_unary(
qvar: QArray
) -> None</code></pre>

Inplace conversion of one-hot encoded value to unary encoding.
The input is assumed to be of size n, where n is the number of bits in the one-hot representation.
The remaining unary representation will at the higher n-1 bits, where the lsb is cleared to 0.
For example, the state `|0010>` (one-hot for 2) will be converted to `|0>``|110>` (unary for 2).

**Parameters:**

| Name   | Type     | Description                                            | Default    |
| ------ | -------- | ------------------------------------------------------ | ---------- |
| `qvar` | `QArray` | one-hot input array to be converted to unary encoding. | *required* |

### pad\_zeros

<pre><code>pad\_zeros(
total\_size: int,
qvar: Input\[QArray],
padded: Output\[QArray]
) -> None</code></pre>

Pad the input qvar with additional qubits at the end to reach the total\_size.

**Parameters:**

| Name         | Type             | Description                             | Default    |
| ------------ | ---------------- | --------------------------------------- | ---------- |
| `total_size` | `int`            | The desired total size after padding.   | *required* |
| `qvar`       | `Input[QArray]`  | The input quantum array to be padded.   | *required* |
| `padded`     | `Output[QArray]` | The output quantum array after padding. | *required* |
