Popcount & Bit Length Calculator
Count how many 1-bits an integer has, measure its bit length, and instantly see whether it is a power of two.
Input base
bits
Hamming weight of the binary representation
8
bitsSet bits (1s)
50%
Zero bits (0s)
50%
- 1
Binary representation
10011100Bit length: 8 - 2
Set bits (1s counted)
count of 1s in 10011100 = 4
How does this calculator work?
Popcount is the count of 1-bits (Hamming weight) in an integer, found by shifting and masking each bit. Bit length is the position of the highest set bit. A number is a power of two exactly when its popcount equals 1. Enter n in decimal or binary to see all four values instantly.
Formula
How this is calculated
Enter a non-negative integer n in either decimal or binary form. The value is parsed as an arbitrary-precision integer, so very large numbers work without overflow. The popcount (also called the Hamming weight) is the count of 1-bits: repeatedly inspect the lowest bit with n & 1 and shift right with n >> 1 until n reaches zero, adding up the set bits along the way.
The bit length is the number of bits needed to represent n, equal to the position of its highest set bit (n = 0 has bit length 0). The optional width field sets a fixed field size w; the number of zero bits is then w − popcount. If you leave the width blank it defaults to the bit length, so the zero count reflects only the bits inside the number itself.
A number is a power of two exactly when it has a single set bit, i.e. popcount = 1 (so 1, 2, 4, 8, 16, … qualify, but 0 does not). All counts are exact integers; if the width you supply is smaller than the bit length, it is raised to the bit length so the zero count never goes negative.
Frequently asked questions
Popcount is the number of bits set to 1 in the binary representation of a number. It is also called the Hamming weight and is widely used in error-correction, hashing, and low-level optimization.
Zero has no set bits, so its bit length is 0 and its popcount is 0. Every positive integer has bit length equal to one plus the index of its highest set bit.
A power of two has a single 1-bit followed by zeros (1, 10, 100, 1000 in binary). Since only one bit is set, its popcount is exactly 1, which is the quickest way to test the property.
Also known as
TG we-Calculate Editorial Team. (2026). Popcount & Bit Length Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/popcount-bit-length-calculator
TG we-Calculate Editorial Team. "Popcount & Bit Length Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/popcount-bit-length-calculator.
TG we-Calculate Editorial Team, "Popcount & Bit Length Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/popcount-bit-length-calculator
@misc{wecalculate_popcount_bit_length_calculator, title = {Popcount & Bit Length Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/popcount-bit-length-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
