🔢 SetBitCount
Count set bits in a single number or across a range of natural numbers — simple, fast and Pythonic.
💡 What is a Set Bit?
A set bit is a binary digit that is 1.
For example:
3 in binary = 011 → 2 set bits
7 in binary = 111 → 3 set bits
This package counts set bits in a single number or across an entire range of natural numbers in one call.
📦 Installation
pip install setbitcounter-pkg
🚀 Usage
from setbitcounter.countset import countsetbit
Count set bits in a single number:
from setbitcounter.countset import countsetbit
print(countsetbit(3))
# Output: 2
# Because 3 = 011 in binary → 2 set bits
Count set bits across a range:
from setbitcounter.countset import countsetbit
print(countsetbit(1, 7))
# Output: 12
# Counts all set bits in numbers 1, 2, 3, 4, 5, 6, 7
🧠 How the Range Works
| Number | Binary | Set Bits |
|---|---|---|
| 1 | 001 | 1 |
| 2 | 010 | 1 |
| 3 | 011 | 2 |
| 4 | 100 | 1 |
| 5 | 101 | 2 |
| 6 | 110 | 2 |
| 7 | 111 | 3 |
| Total | 12 |
📬 Connect
Diksha Rawat | LinkedIn
dev.to/diksharawat | Dev.to
Built with curiosity and Python 🐍
Release files for setbitcounter-pkg 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| setbitcounter_pkg-1.1.1.tar.gz | 3.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| setbitcounter_pkg-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.8 kB
Release files / setbitcounter_pkg-1.1.1.tar.gz
| Download URL | setbitcounter_pkg-1.1.1.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f1d43497ae8e2622b8ec96d903f12169e3474cca9f8256f4f630df76b683160
|
|
BLAKE2b-256 checksum How to use checksums |
082fc24b41fac7b19f49817c5c61254382ec094e4a410f1b06723f23311833c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / setbitcounter_pkg-1.1.1-py3-none-any.whl
| Download URL | setbitcounter_pkg-1.1.1-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e47456a26184d2cd17d476cf03a5636c4db4532ef951add9687ea90a9ee03b8c
|
|
BLAKE2b-256 checksum How to use checksums |
10b44a476475d97f91f8d3afe027c0d02aeff3dffef4a87ad10f0cd10c862fae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|