The question is edited based on the @Damien comment.
Question:
Is there a direct formula (not recursive) for counting 1s in binary form of a positive integer?
For example, suppose the formula is called $f(n)$ for a positive integer $n$. Then, we have
$f(3)=2$, $f(13)=3$ and $f(16)=1$, since we have $[3]_2=11$,$[13]_2=1101$ and $[16]_2=10000$.
Thank you in advance