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

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/functions-reference/string/to_bin",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> Reference material for the TO_BIN function

# TO_BIN

export const QueryWindow = ({content}) => {
  const {sql, result} = content;
  const [inited, setInited] = useState(false);
  const buttonRef = useRef(null);
  useEffect(() => {
    if (!inited && buttonRef.current) {
      runQuery(buttonRef.current, true);
      setInited(true);
    }
  }, []);
  return <div className="query-window">
      <div className="query-toolbar">
        <button className="run-button" onClick={ev => runQuery(ev.target)} ref={buttonRef}>Run Query</button>
        <span className="window-title">Interactive SQL Playground 🔥</span>
      </div>
      <div className="query-content">
        <pre><code className="firebolt-sql language-sql" contentEditable="true" spellCheck="false" data-original-query={sql}>{sql}</code></pre>
        <script type="application/json" className="fallback-result" style={{
    display: "none"
  }}>{JSON.stringify(result)}</script>
        <div className="server-unavailable-banner query-window-hidden">
          The Firebolt playground server is currently unavailable. Using precomputed query results.
        </div>
        <div className="query-results"></div>
      </div>
    </div>;
};

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

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
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:

<QueryWindow
  content={{
"sql": "SELECT TO_BIN(5) as result",
"result": {
"data": [
  [
    "101"
  ]
],
"meta": [
  {
    "name": "result",
    "type": "text"
  }
],
"query": {
  "query_id": "to-bin-example-1",
  "query_label": null,
  "request_id": "to-bin-request-1"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.008,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.0002,
  "time_to_execute": 0.0001
}
}
}}
/>

<QueryWindow
  content={{
"sql": "SELECT TO_BIN(-1) as result",
"result": {
"data": [
  [
    "11111111111111111111111111111111"
  ]
],
"meta": [
  {
    "name": "result",
    "type": "text"
  }
],
"query": {
  "query_id": "to-bin-example-2",
  "query_label": null,
  "request_id": "to-bin-request-2"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.008,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.0002,
  "time_to_execute": 0.0001
}
}
}}
/>

<QueryWindow
  content={{
"sql": "SELECT TO_BIN(0) as result",
"result": {
"data": [
  [
    "0"
  ]
],
"meta": [
  {
    "name": "result",
    "type": "text"
  }
],
"query": {
  "query_id": "to-bin-example-3",
  "query_label": null,
  "request_id": "to-bin-request-3"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.008,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.0002,
  "time_to_execute": 0.0001
}
}
}}
/>

<QueryWindow
  content={{
"sql": "SELECT TO_BIN(NULL) as result",
"result": {
"data": [
  [
    null
  ]
],
"meta": [
  {
    "name": "result",
    "type": "text null"
  }
],
"query": {
  "query_id": "to-bin-example-4",
  "query_label": null,
  "request_id": "to-bin-request-4"
},
"rows": 1,
"statistics": {
  "bytes_read": 1,
  "elapsed": 0.008,
  "rows_read": 1,
  "scanned_bytes_cache": 0,
  "scanned_bytes_storage": 0,
  "time_before_execution": 0.0002,
  "time_to_execute": 0.0001
}
}
}}
/>
