Documentation

    bit_count

    Returns the number of bits that are set.

    Try an expression

    In 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.

    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.

    Browse numbersDuckDB documentation

    Function metadata from DuckDB, used under the MIT license.