Hamming Weight Calculator
Enter a number and select its base.
Result
How it is calculated
You type a non-negative whole number and choose its base: decimal, hexadecimal or binary. The tool converts the value to an exact binary string and counts the 1-bits: weight = number of 1s in the binary form. It also shows the binary string and its length in bits, without leading zeros (zero itself is one bit long, 0). A leading 0x or 0b is accepted in hex and binary mode only. Anything else, such as a minus sign, a decimal point, a comma, a space or a digit not valid in the chosen base, gives no result. The value must fit in 64 bits, up to 18,446,744,073,709,551,615 (FFFFFFFFFFFFFFFF in hex); a longer value shows no result. Because the conversion works on digit strings, large values are exact.
Worked example
Take DEADBEEF in hexadecimal. Each hex digit is four bits: D = 1101 (three 1s), E = 1110 (three), A = 1010 (two), D (three), B = 1011 (three), E (three), E (three), F = 1111 (four). Sum: 3 + 3 + 2 + 3 + 3 + 3 + 3 + 4 = 24. The binary form is 11011110101011011011111011101111, which the tool reports as 32 bits long, so 24 of its 32 bits are set and 8 are clear.
Common mistakes
- Leaving the base on decimal while typing a hex or binary value: 1011 in decimal is the number one thousand eleven (weight 8), while 1011 in binary is eleven (weight 3).
- Counting leading zeros. They are not shown, are not part of the bit length, and never change the weight.
- Entering a negative number. The tool does not apply two's complement and gives no result for a minus sign, so work out the bit pattern first and enter it in hex or binary.
- Typing a number with separators such as 1,024 or 1 024. Commas and spaces are not allowed, only digits.
- Putting a
0xprefix on a number while the base is set to decimal. The prefix is only accepted in hex mode (and0bin binary mode), so the entry is rejected.
About this calculator
The Hamming weight of a number — also called its population count or popcount — is simply the count of 1-bits in its binary representation. For example, the decimal number 13 is 1101 in binary, giving it a Hamming weight of 3. This calculator accepts a number in decimal, hexadecimal, or binary and counts its set bits directly.
Popcount is a workhorse operation in computer science and digital electronics: it measures the “distance” between two binary codes in error-detecting and error-correcting codes (the Hamming distance between two values is the popcount of their XOR), it underlies bit-manipulation tricks in cryptography and hashing, and it appears in digital signal processing and chess-engine bitboards, where CPUs even provide a dedicated POPCNT instruction because the operation is so common.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
This counts the ones in a single value, so to get the Hamming distance between two words you first combine them with XOR yourself. XOR of F0 and CC is 3C in hex, and entering 3C returns a weight of 4, so those two bytes differ in four bit positions. Values up to 64 bits are accepted, and leading zeros do not change the weight. Which word size do you work with, and would wider values help?