Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32133

Re: bit count or bit set && Python3

From Christian Heimes <christian@python.org>
Subject Re: bit count or bit set && Python3
Date 2012-10-25 17:25 +0200
References <5089511E.4090009@earthlink.net>
Newsgroups comp.lang.python
Message-ID <mailman.2848.1351178765.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: bit count or bit set && Python3 Christian Heimes <christian@python.org> - 2012-10-25 17:25 +0200

csiph-web