Skip to main content

Count set bits in a number or range of natural numbers

Project description

🔢 SetBitCount

Count set bits in a single number or across a range of natural numbers — simple, fast and Pythonic.

PyPI License: MIT


💡 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 🐍

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

setbitcounter_pkg-1.1.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

setbitcounter_pkg-1.1.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file setbitcounter_pkg-1.1.1.tar.gz.

File metadata

  • Download URL: setbitcounter_pkg-1.1.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for setbitcounter_pkg-1.1.1.tar.gz
Algorithm Hash digest
SHA256 0f1d43497ae8e2622b8ec96d903f12169e3474cca9f8256f4f630df76b683160
MD5 d0c88e6b7d95fad9d18f5c9004e104b3
BLAKE2b-256 082fc24b41fac7b19f49817c5c61254382ec094e4a410f1b06723f23311833c8

See more details on using hashes here.

File details

Details for the file setbitcounter_pkg-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for setbitcounter_pkg-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e47456a26184d2cd17d476cf03a5636c4db4532ef951add9687ea90a9ee03b8c
MD5 7fa84a1697ee3d4acc5aa9701d304b0e
BLAKE2b-256 10b44a476475d97f91f8d3afe027c0d02aeff3dffef4a87ad10f0cd10c862fae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page