> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# BIT_COUNT

> Counts the set bits in an integer.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL when an argument is NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
bit_count(value)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | INTEGER | Yes | The integer whose binary representation is counted. |

## Returns

* Type: INT
* Possible values: An integer from 0 through 64.
* NULL behavior: Returns NULL when an argument is NULL.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Signed inputs are sign-extended to 64 bits before counting; negative TINYINT, SMALLINT and INT operands therefore count the 64-bit representation.
* Use the numeric input types listed above. BOOLEAN is not a supported SQL input.

## Examples

### Set bits and signed representation

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT bit_count(7) AS bits, bit_count(CAST(-1 AS BIGINT)) AS signed_bits, bit_count(CAST(NULL AS BIGINT)) AS null_value;
```

| bits | signed\_bits | null\_value |
| - | - | - |
| 3 | 64 | NULL |

### Zero and positive integers

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT bit_count(CAST(0 AS INT)) AS no_set_bits, bit_count(CAST(15 AS INT)) AS four_set_bits;
```

| no\_set\_bits | four\_set\_bits |
| - | - |
| 0 | 4 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.