The Python Oracle

Fast way of counting non-zero bits in positive integer

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle

--

Chapters
00:00 Question
01:18 Accepted answer (Score 149)
02:38 Answer 2 (Score 133)
03:03 Answer 3 (Score 37)
04:28 Answer 4 (Score 22)
04:54 Thank you

--

Full question
https://stackoverflow.com/questions/9829...

Accepted answer links:
[gmpy]: http://code.google.com/p/gmpy/

Answer 2 links:
[int.bit_count()]: https://docs.python.org/3.10/library/std...
[~6 times faster]: https://github.com/python/cpython/pull/7...
[Issue29882]: https://bugs.python.org/issue29882

Answer 4 links:
[post]: https://stackoverflow.com/questions/1090...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #binary #counting

#avk47