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

# CODE

```python
class Solution:
    def hammingWeight(self, n: int) -> int:
        result = 0
        while n > 0:
            result += n & 1
            n >>= 1
        return result
```
