bit_count function (Databricks SQL)

Returns the number of bits set in the argument.

Syntax

bit_count(expr)

Arguments

  • expr: A BIGINT or BOOLEAN expression.

Returns

An INTEGER.

Examples

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