Population count (set bits) calculator
Count the one bits in a non-negative integer’s binary representation. Enter your values below to see the result and method.
inputs.
Related calculators and articles
Compare methods and explore more free tools in computer science.
How to use the Population count (set bits) calculator
Count the one bits in a non-negative integer’s binary representation. Use the free tool above without creating an account.
What it calculates
Count the one bits in a non-negative integer’s binary representation. The result counts one bits in the integer’s binary representation. It is independent of leading zero padding, but the input must be an integer in the supported range.
Inputs and units
Enter Non-negative integer. Review the labels and example values before calculating.
- Non-negative integer: enter a value in the unit shown; the browser checks the accepted format and range.
Formula and method
popcount(n) = number of set bits in binary n
The calculator applies this relationship directly and keeps intermediate values unrounded for the displayed estimate.
Worked example
255 is 11111111₂, so its population count is 8.
How to interpret the result
Use the result to answer the specific sizing, encoding, performance, or representation question stated on this page. It is conditional on the chosen inputs; change one input at a time to see how the estimate responds.
Assumptions and limitations
The input is treated as a non-negative safe integer. This is a count of binary one bits, not the number of decimal digits.
Frequently asked questions
What does population count return?
It counts the 1 bits in the non-negative integer’s binary representation. For example, 255 is 11111111₂, so its population count is 8.
Does leading-zero padding change the count?
No. Leading zeros add no set bits, so the population count depends on the integer value rather than the width used to display its binary form.
What input range is supported?
Enter a non-negative integer within the calculator’s supported safe-integer range; fractional and negative values are outside this bit-count interpretation.
How do I use the Population count (set bits) calculator?
Enter Non-negative integer. Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Population count (set bits)?
255 is 11111111₂, so its population count is 8.
Read the calculation methodology and privacy policy.