> ## 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.

# 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` | 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>`binary_to_one_hot(
binary: Input[QNum],
one_hot: Output[QArray]
) -> None`</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>`binary_to_unary(
binary: Input[QNum],
unary: Output[QArray]
) -> None`</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>`one_hot_to_unary(
one_hot: Input[QArray],
unary: Output[QArray]
) -> None`</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>`one_hot_to_binary(
one_hot: Input[QArray],
binary: Output[QNum[Literal['ceiling(log(one_hot.len, 2))']]]
) -> None`</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>`unary_to_one_hot(
unary: Input[QArray],
one_hot: Output[QArray]
) -> None`</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>`unary_to_binary(
unary: Input[QArray],
binary: Output[QNum]
) -> None`</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>`inplace_binary_to_one_hot(
source: Input[QArray],
target: Output[QArray]
) -> None`</pre>

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 |
| - | - | - | - |
| `source` | `Input[QArray]` | binary input array padded with 0's to be converted to one-hot encoding. | *required* |
| `target` | `Output[QArray]` | one-hot output array. | *required* |

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

<pre>`inplace_one_hot_to_unary(
qvar: QArray
) -> None`</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>`pad_zeros(
total_size: int,
qvar: Input[QArray],
padded: Output[QArray]
) -> None`</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* |


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