Bit Counting Tool

Population Count Calculator

Enter a binary value and instantly count how many bits are set to 1. Also see the number of zero bits, total bit length, set-bit positions, and percentage of bits that are set.

Count 1 bits Hamming weight Set-bit positions
Count Set Bits in a Binary Value
Leading zeros are preserved and included in the bit length.
Popcount 5
Analyzed binary 10110110
5 of 8 bits are set to 1.
1 Bits 5
0 Bits 3
Bit Length 8 bits
Bit Density 62.5%
Set-bit positions — LSB = position 0
7, 5, 4, 2, 1
Popcount

What Is a Population Count?

Population count, commonly shortened to popcount, is the number of bits set to 1 in a binary value.

For example, the binary value 10110110 contains five 1 bits. Its population count is therefore 5. The operation ignores the numerical size of each bit position and simply counts how many positions contain a set bit.

Population count is also closely associated with the term Hamming weight. In a binary string, Hamming weight is the number of nonzero symbols, which is the same as the number of 1 bits.

Population count popcount(x) = number of 1 bits in x
How to Use

How to Count 1 Bits in Binary

1
Enter the binary value Type the sequence of 0 and 1 bits you want to analyze.
2
Click Count 1 Bits The calculator scans the complete binary sequence and counts every set bit.
3
Read the population count The main result shows exactly how many positions contain the digit 1.
4
Check the bit details You can also view zero count, total length, bit density, and the positions of all set bits.
Worked Example

Population Count of 10110110

To find the population count manually, inspect each binary digit and count only the positions containing 1.

Count the set bits
Binary value: 10110110 Set bits: 1 0 1 1 0 1 1 0 ↑ ↑ ↑ ↑ ↑ Number of 1 bits = 5 Population count = 5 Hamming weight = 5
Set & Clear Bits

What Are 1 Bits and 0 Bits?

In bit terminology, a binary digit with value 1 is commonly called a set bit. A bit containing 0 is often described as a cleared or unset bit.

If an 8-bit value has a population count of 5, then five bits are set and the remaining three bits are zero. This relationship makes the zero count easy to calculate once the total bit length is known.

Zero-bit count zero bits = bit length − popcount
Reference Examples

Binary Population Count Examples

Binary Value Bit Length 1 Bits 0 Bits Popcount
0 1 0 1 0
1 1 1 0 1
1010 4 2 2 2
1111 4 4 0 4
10000000 8 1 7 1
10101010 8 4 4 4
11110000 8 4 4 4
11111111 8 8 0 8
Hamming Weight

Population Count vs Hamming Weight

For a binary sequence, population count and Hamming weight normally refer to the same basic quantity: the number of positions containing 1.

For example, the Hamming weight of 1100101 is 4 because four digits are nonzero. The population count of that same binary sequence is also 4.

Hamming weight should not be confused with Hamming distance. Hamming weight analyzes one sequence, while Hamming distance counts positions that differ between two equal-length sequences.
Bit Positions

Finding the Positions of Set Bits

Binary bit positions are usually numbered from right to left beginning with position 0. The rightmost bit is the least significant bit, or LSB. The next bit is position 1, followed by position 2, and so on.

For example, 10110 has set bits at positions 4, 2, and 1. Therefore its population count is 3.

Position numbering
Binary: 1 0 1 1 0 Position: 4 3 2 1 0 Set-bit positions: 4, 2, 1 Popcount = 3
Bit Density

What Is Set-Bit Density?

Set-bit density expresses the proportion of a binary sequence that contains 1 bits. It is useful when comparing binary values of different lengths.

Bit density density = (1 bits ÷ total bits) × 100%

For example, 11110000 contains four 1 bits among eight total bits. Its set-bit density is therefore 50%.

Leading Zeros

Do Leading Zeros Affect Population Count?

Leading zeros do not increase the population count because they are not set bits. However, they do affect the total bit length and therefore can change the zero count and bit-density percentage.

For example, 1111 and 00001111 both have a population count of 4. The first value has a bit length of 4 and 100% set-bit density, while the second has a bit length of 8 and 50% density.

This calculator deliberately preserves leading zeros so it can analyze fixed-width bit patterns correctly.

Applications

Where Population Count Is Used

Bit Masks

Count how many flags or options are enabled inside a binary bit mask.

Algorithms

Popcount appears in bit-manipulation algorithms, combinatorics, and optimized integer operations.

Error Detection

Bit counts and Hamming weights are useful concepts in coding and error-detection systems.

Data Analysis

Measure how sparse or dense a binary pattern is by counting its active bits.

Permissions & Flags

Count active permission bits or feature flags represented inside a bit field.

Programming

Verify the output of built-in or custom popcount operations in software.

Programming

Population Count in Computer Programming

Population count is common enough that many processors and programming environments provide optimized ways to perform it. Some CPU instruction sets include a dedicated population-count instruction, while programming languages and libraries may expose equivalent bit-count functions.

A simple software implementation can examine each bit individually and increment a counter whenever a 1 is found. More optimized approaches use bitwise operations, lookup tables, parallel bit techniques, or dedicated processor instructions.

For learning and verification, the essential definition remains simple: count every set bit in the selected binary representation.

Common Mistakes

Common Popcount Mistakes

Counting the decimal value

Population count is not the numerical value of the binary number. For example, 1011₂ equals decimal 11, but its population count is only 3.

Counting all digits

Popcount counts only the digits equal to 1. Total digits are the bit length, which is a different measurement.

Removing leading zeros when width matters

Leading zeros do not affect popcount, but removing them changes the bit length and zero-bit count. Fixed-width bit patterns should therefore preserve them.

Confusing Hamming weight and Hamming distance

Hamming weight counts set bits in one binary sequence. Hamming distance compares two sequences and counts the positions where they differ.

FAQ

Population Count Calculator FAQs

Population count, or popcount, is the total number of bits equal to 1 in a binary value.
10110110 contains five 1 bits, so its population count is 5.
For a binary sequence, yes. Both commonly describe the number of set or 1 bits in that sequence.
All eight bits are set, so the population count of 11111111 is 8.
There are no 1 bits, so the population count is 0.
No. Leading zeros do not add any set bits. They do, however, increase the total bit length and zero-bit count.
A set bit is a binary digit whose value is 1. A bit with value 0 is commonly called cleared or unset.
Bit positions are normally counted from right to left starting at 0. The rightmost bit is position 0.
Bit length counts every binary digit, while popcount counts only the digits whose value is 1.
Set-bit density is the percentage of all bit positions that contain 1. It is calculated as popcount divided by bit length, multiplied by 100.
Hamming weight counts nonzero bits in one sequence. Hamming distance counts the positions that differ between two equal-length sequences.
Yes. The calculator counts the characters directly instead of converting the input to a standard JavaScript integer, so long binary strings can be analyzed without ordinary integer precision loss.
Scroll to Top