> For the complete documentation index, see [llms.txt](https://quenluo.gitbook.io/leecode-python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quenluo.gitbook.io/leecode-python/191.-number-of-1-bits.md).

# 191. Number of 1 Bits

## Question 191

<https://leetcode.com/problems/number-of-1-bits/description/>

Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the [Hamming weight](http://en.wikipedia.org/wiki/Hamming_weight)).

**Example 1:**

```
Input: 11
Output: 3
Explanation: Integer 11 has binary representation 00000000000000000000000000001011 
```

### Answer&#x20;

```python
class Solution(object):
    def hammingWeight(self, n):
        AnswerINT = 0
        while(n):
            if(n%2):
                AnswerINT += 1
            n = n // 2
        return AnswerINT
```
