mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
18 lines
280 B
Python
18 lines
280 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
def count_ones(n: int) -> int:
|
|
|
|
counter = 0
|
|
|
|
while n:
|
|
|
|
if n & 1:
|
|
counter += 1
|
|
|
|
n >>= 1
|
|
|
|
return counter
|