---
title: bin
description: "bin function in PySpark: Returns the string representation of the binary value of the given column."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/bin
---

# bin

Returns the string representation of the binary value of the given column. Supports Spark Connect.

For the corresponding Databricks SQL function, see [`bin` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/bin.md).

## Syntax

```python
from pyspark.sql import functions as dbf

dbf.bin(col=<col>)
```

## Parameters

| Parameter | Type                          | Description               |
| --------- | ----------------------------- | ------------------------- |
| `col`     | `pyspark.sql.Column` or `str` | Target column to work on. |

## Returns

`pyspark.sql.Column`: binary representation of given value as string.

## Examples

```python
from pyspark.sql import functions as dbf
spark.range(10).select("*", dbf.bin("id")).show()
```

```Output
+---+-------+
| id|bin(id)|
+---+-------+
|  0|      0|
|  1|      1|
|  2|     10|
|  3|     11|
|  4|    100|
|  5|    101|
|  6|    110|
|  7|    111|
|  8|   1000|
|  9|   1001|
+---+-------+
```
