Skip to main content

bit_count function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Returns the number of bits set in the argument.

To count bits in a BINARY expression use bitmap_count function.

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