bit count or bit set && Python3

Christian Heimes christian at python.org
Thu Oct 25 11:25:47 EDT 2012


Am 25.10.2012 16:47, schrieb Charles Hixson:
> In Python3 is there any good way to count the number of on bits in an
> integer (after an & operation)?


Simple, easy, faster than a Python loop but not very elegant:

   bin(number).count("1")

Christian





More information about the Python-list mailing list