bit count
The node that counts 1-bits for no good reason until you need it
- INT
This is a node you will ignore for months and then suddenly need at 11pm. "Bit count" from the Basic data handling pack takes an integer and returns the number of 1 bits in its binary representation - the population count, the thing C programmers call __builtin_popcount. It sounds like trivia until you're working with bitmask flags or packed data, at which point it's exactly the tool you want.
What it does
An integer is just a pile of bits to a computer. 10 in binary is 1010, which has two 1 bits, so bit count of 10 is 2. 255 is 11111111 - eight 1s, so the answer is 8. 0 has zero 1s, so it returns 0. It's a pure Python int.bit_count() call, added to the language in Python 3.10.
Real-world uses in ComfyUI are niche but real: checksum-like sanity checks on generated values, working with packed flag fields where each bit means something, or just verifying that a binary string parsed from bytes actually contains the bits you expected.
Inputs and outputs
int_value- INT, default0. The integer to inspect.- Output
INT- the count of set (1) bits.
That's it. One in, one out.
Install
From the Basic data handling pack. ComfyUI Manager → search "Basic data handling" → install → restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
then restart ComfyUI. Zero dependencies, no models to download.
The gotcha that actually matters
int.bit_count() requires Python 3.10 or newer. Modern ComfyUI installs run 3.10+, so for most people this just works - but if you're on a distro packaging an older Python, this node will throw a AttributeError the first time you run it. It's the one node in this pack where the Python version genuinely matters. If you see that error, check your Python before suspecting the node.
Also worth knowing it exists at all: bit count and its sibling bit length are the only two bit-introspection nodes in the pack, and they're often used together - count the 1s, then measure how wide the value is, when you're reverse-engineering a packed value from bytes.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| int_value | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |