Binary Ones Count

Numbers are stored inside computers in binary form, and sometimes you need to know how many 1 bits they contain. Given a non-negative integer n, return the number of 1s in its binary representation. For example, 7 has three set bits in binary. For 0, the answer is 0.

Примеры

Ввод
0
Вывод
0
Ввод
7
Вывод
3
Ввод
255
Вывод
8

Нужно реализовать

def count_set_bits(n):

Теги

mathrecursion
PostgreSQLv16

Her vises resultatet af din kode

Visible tests
1
Input
0
Expected0
2
Input
7
Expected3
3
Input
255
Expected8
4
Input
1024
Expected1
5
Input
2863311530
Expected16
6
Input
1
Expected1
Focus radio
Paused · SomaFM · Fluid