BIT_COUNT()

All functions > BITWISE > BIT_COUNT()

Returns the number of 1-bits in the two’s-complement binary representation of an integer.

Signatures

Integer popcount

Returns: Number of bits set to 1

BIT_COUNT(value: T) → BIGINT
sql
ParameterTypeRequiredDescription
valueTYesInteger to count set bits in

With:

  • T : Integer type (TINYINT … BIGINT)

Signature notes:

  • Returns NULL if the input is NULL
  • Interprets the value as a signed integer in two’s-complement form

Examples

FeatureQL
SELECT
    f1 := BIT_COUNT(0), -- No bits set
    f2 := BIT_COUNT(7), -- Binary 111
    f3 := BIT_COUNT(-1) -- All bits set in 64-bit representation
;
Result
f1 BIGINTf2 BIGINTf3 BIGINT
0364

Last update at: 2026/05/26 17:22:09