Binary Hamming Weight Calculator
Calculate the Hamming weight of a binary number instantly. Enter any binary bit string to count the number of 1 bits, number of zeros, total bit length, and percentage of set bits.
What Is Hamming Weight?
The Hamming weight of a binary string is the number of positions that contain
the bit 1.
How to Calculate Binary Hamming Weight
1. Read the Binary String
Check that every character is either 0 or 1.
2. Count Every 1
Each occurrence of the digit 1 contributes one to the Hamming weight.
3. Ignore 0s for the Weight
Zero bits do not increase the Hamming weight.
4. Return the Total
The number of 1 bits is the final Hamming weight.
Hamming Weight Examples
| Binary | 1 Bits | 0 Bits | Hamming Weight |
|---|---|---|---|
0 | 0 | 1 | 0 |
1 | 1 | 0 | 1 |
10 | 1 | 1 | 1 |
11 | 2 | 0 | 2 |
100 | 1 | 2 | 1 |
101 | 2 | 1 | 2 |
111 | 3 | 0 | 3 |
1000 | 1 | 3 | 1 |
1010 | 2 | 2 | 2 |
1111 | 4 | 0 | 4 |
11001 | 3 | 2 | 3 |
101010 | 3 | 3 | 3 |
11111111 | 8 | 0 | 8 |
Example: Hamming Weight of 11001
Hamming Weight vs Bit Length
Hamming weight and bit length measure different properties of a binary string.
| Measurement | Meaning | 11001 |
|---|---|---|
| Bit Length | Total number of bits | 5 |
| Hamming Weight | Number of 1 bits | 3 |
| Zero Count | Number of 0 bits | 2 |
Hamming Weight vs Hamming Distance
Hamming weight measures one bit string, while Hamming distance compares two equal-length bit strings.
Are Leading Zeros Counted?
Leading zeros do not change the Hamming weight because they add zero set bits, but they do increase the supplied bit-string length and zero count.
What Is Set-Bit Percentage?
Set-bit percentage shows what fraction of the supplied binary positions are 1.
11001:
(3 ÷ 5) × 100 = 60%
Where Is Hamming Weight Used?
Bit Manipulation
Programs often need to count how many flags or bit positions are enabled.
Error-Correcting Codes
Hamming-weight concepts appear in coding theory and digital communication.
Cryptography
Bit distributions and differences can be relevant in cryptographic analysis.
Computer Algorithms
Population count operations are frequently used in low-level algorithms.
Common Hamming Weight Mistakes
Counting All Bits
Hamming weight counts only the 1 bits, not every binary position.
Confusing Weight with Distance
Weight applies to one string; distance compares two strings.
Removing Leading Zeros First
It is unnecessary for weight calculation because leading zeros contribute zero anyway.
Counting Decimal Digits
The calculation applies to the actual binary bit string, not its decimal value.
Related BinaryCon Tools
Binary Hamming Weight Calculator FAQs
What is the Hamming weight of a binary number?
What is the Hamming weight of 11001?
11001 contains three 1 bits, so its Hamming weight is 3.