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


Groups > comp.lang.python > #32133 > unrolled thread

Re: bit count or bit set && Python3

Started byChristian Heimes <christian@python.org>
First post2012-10-25 17:25 +0200
Last post2012-10-25 17:25 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#32133 — Re: bit count or bit set && Python3

FromChristian Heimes <christian@python.org>
Date2012-10-25 17:25 +0200
SubjectRe: bit count or bit set && Python3
Message-ID<mailman.2848.1351178765.27098.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web