Hamming Weight Calculator

Hamming Weight Calculator calculator can be used to determine the number of 1s in the binary representation of a given integer.

Input Parameters

Calculation Results

Hamming Weight

0

The Hamming Weight is the number of 1s in the binary representation of the input integer.

Hamming Weight Calculator Usage Guide

Learn how to use the Hamming Weight Calculator and its working principles

How to Use the Hamming Weight Calculator

  1. Enter an integer in the input field.
  2. Click the "Calculate" button to compute the Hamming Weight.
  3. The result will be displayed in the Hamming Weight field.

Hamming Weight Calculation Formula

The Hamming Weight of an integer is the number of 1s in its binary representation. For example, the Hamming Weight of the integer 9 (binary 1001) is 2.

The calculation is done by repeatedly checking the least significant bit of the integer and shifting the integer right by one bit until it becomes zero. Each time the least significant bit is 1, the Hamming Weight is incremented.

Example

Input: 9 (binary 1001)

Calculation Steps:

  • 1001 & 1 = 1 (Hamming Weight = 1)
  • 1001 >> 1 = 100 (Hamming Weight = 2)
  • 100 & 1 = 0 (Hamming Weight remains 2)
  • 100 >> 1 = 10 (Hamming Weight remains 2)
  • 10 >> 1 = 1 (Hamming Weight = 3)
  • 1 >> 1 = 0 (Hamming Weight remains 3)

Output: 3