---
title: bit_count function
description: Learn the syntax of the bit\_count function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/bit_count
---

# `bit_count` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the number of bits set in the argument.

To count bits in a `BINARY` expression use [`bitmap_count` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_count.md).

## Syntax

```
bit_count(expr)
```

## Arguments

* `expr`: A `BIGINT` or `BOOLEAN` expression.

## Returns

An `INTEGER`.

## Examples

```sql
> SELECT bit_count(0);
 0
> SELECT bit_count(5);
 2
> SELECT bit_count(-1);
 64
> SELECT bit_count(true);
 1
```

## Related functions

* [`bitmap_count` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_count.md)
* [`|` (pipe sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/pipesign.md)
* [`&` (ampersand sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/ampersandsign.md)
* [`^` (caret sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/caretsign.md)
* [`~` (tilde sign) operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/tildesign.md)
