---
title: "bit_count function in Strata | Oplema"
description: "Count how many bits are set to 1 in an integer or bitstring. For example, bit_count(31) returns 5. Works in a Strata Formula or Filter."
url: "https://oplema.com/docs/strata/functions/bit-count"
updated: "2026-11-04"
---

# bit\_count

Returns the number of bits that are set.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **BIGINT**.

### Expression

```
bit_count(31)
```

### Result

```
5
```

The expression returns `TINYINT`. Formula stores it as `BIGINT` in this example. To use your own data, replace the example values with column names. Keep format strings and other options as written.

Try it live in Formula

Result
| id | result |
| --- | --- |
| 1 | 5 |

## Arguments and types

```
bit_count(x)
```

**x**

Number, Bits

Supported signatures (6)

```
bit_count(x: BIGINT) → TINYINT
bit_count(x: BIT) → BIGINT
bit_count(x: HUGEINT) → TINYINT
bit_count(x: INTEGER) → TINYINT
bit_count(x: SMALLINT) → TINYINT
bit_count(x: TINYINT) → TINYINT
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

If the first argument is missing, the result is NULL.

## Related functions

[isnan

Check whether a number is NaN, the special "not a number" value.

](https://oplema.com/docs/strata/functions/isnan)[random

Return a random number between 0 and 1. Each row gets a new value.

](https://oplema.com/docs/strata/functions/random)[cbrt

Calculate the cube root of a number.

](https://oplema.com/docs/strata/functions/cbrt)[ceil

Round a number up to the nearest whole number.

](https://oplema.com/docs/strata/functions/ceil)

[Browse numbers](https://oplema.com/docs/strata/functions#numbers) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/numeric.html#bit_countx)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
