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
| Parameter | Type | Required | Description |
|---|---|---|---|
value | T | Yes | Integer 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 BIGINT | f2 BIGINT | f3 BIGINT |
|---|---|---|
| 0 | 3 | 64 |
On this page