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

> Reference material for the TO_BIN function

# TO_BIN

Converts a value (`<expression>`) of type `INTEGER` or `BIGINT` to its equivalent two's complement binary representation.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
TO_BIN(<expression>)
```

## Parameters

| Parameter      | Description                                                                      | Supported input types |
| :------------- | :------------------------------------------------------------------------------- | :-------------------- |
| `<expression>` | A value expression evaluating to `INTEGER` or `BIGINT` that should be converted. | `INTEGER`, `BIGINT`   |

## Return Type

`TEXT`

* Returns `NULL` if the input is `NULL`

## Remarks

The function returns the binary representation of the input number as a text string.
Negative numbers are represented using two's complement notation.
Leading zeros are omitted, but the output is at least one digit long.

## Example

The following examples convert integer values to their binary representations:

<div className="query-window">
  ```
  SELECT TO_BIN(5) as result
  ```

  | result <span>text</span> |
  | :----------------------- |
  | 101                      |

  <p><span>Rows: 1</span><span>Execution time: 6.08ms</span></p>
</div>

<div className="query-window">
  ```
  SELECT TO_BIN(-1) as result
  ```

  | result <span>text</span>         |
  | :------------------------------- |
  | 11111111111111111111111111111111 |

  <p><span>Rows: 1</span><span>Execution time: 5.58ms</span></p>
</div>

<div className="query-window">
  ```
  SELECT TO_BIN(0) as result
  ```

  | result <span>text</span> |
  | :----------------------- |
  | 0                        |

  <p><span>Rows: 1</span><span>Execution time: 5.09ms</span></p>
</div>

<div className="query-window">
  ```
  SELECT TO_BIN(NULL) as result
  ```

  | result <span>text null</span> |
  | :---------------------------- |
  | NULL                          |

  <p><span>Rows: 1</span><span>Execution time: 5.74ms</span></p>
</div>
