Count One Bits
Count 1-bits (Hamming weight) in binary/hex/decimal numbers. Width selector, batch, TSV export. Free, client-side.
Count the number of 1-bits (Hamming weight / popcount) in numbers across binary, hex, or decimal input - auto-detected by default. Per-row breakdown shows binary representation, 1s/0s counts, percentage, and which positions hold the 1-bits.
Summary
Per-row breakdown
How to Use Count One Bits
- Paste numbers, one per line. Auto-detect figures out format per line (binary if all 0s and 1s, hex if hex letters or has
0xprefix, otherwise decimal). - Pick bit width: Natural uses each input's own bit count; fixed widths (8/16/32/64) pad with leading zeros for consistent comparison.
- The table shows binary representation, 1s count, 0s count, total bits, percentage, and the bit positions of 1s (LSB = position 0).
- Download as TSV for spreadsheet analysis.
Frequently Asked Questions
What’s a Hamming weight / popcount?
The Hamming weight of a binary number is the number of 1-bits it contains. Also called population count (popcount) – it’s a primitive operation in many CPUs (the POPCNT instruction). Used in cryptography, error correction, bitset operations, and combinatorial math.
How does auto-detect decide format?
Priority order: 0b... prefix → binary; 0x... prefix → hex; all 0/1 digits → binary; contains a-f → hex; all 0-9 → decimal. Ambiguous strings (e.g., 10 – binary 2 or decimal 10?) get treated as binary. Use explicit format selector or 0x/0b prefixes to disambiguate.
Why does bit width matter?
Natural width counts only the bits actually present (e.g., 0b1010 = 4 bits). Fixed widths pad with leading zeros: 0b1010 at 8-bit = 00001010, still 2 ones but now 6 zeros. The 1s count never changes – only the 0s count and percentage do.
What are bit positions?
Indices where 1-bits sit, counted from the LSB (least significant bit) = position 0. 0b1010 has 1s at positions 1 and 3. Useful for bitmasks, set-theoretic operations, finding which flags are set.
What’s the maximum input value?
JavaScript’s BigInt handles arbitrary precision, so practically unlimited – limited only by browser memory. A 1000-character binary string parses fine.
How does it handle leading zeros?
Binary input 0001010 has natural width 7 (the leading zeros count toward total bits). Hex 0F has natural width 8 (2 hex chars × 4). Decimal natural width is the minimum bits needed.
What about negative numbers?
Not directly supported as -N. For two’s-complement bit patterns, convert to the appropriate hex or binary form first (e.g., -1 as 8-bit signed = 0xFF).
Why might a line fail?
Lines that don’t match any format (e.g., FFG, five, 3.14) error individually without stopping the batch. The error count appears in stats, and individual error positions show in the status line.
Is anything uploaded?
No. Everything runs in your browser with JavaScript – nothing is sent to a server, logged, or stored, and the tool keeps working offline once the page has loaded.
What’s the row cap?
500 rendered in the table to keep the page responsive. The TSV download includes all rows.