Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32159
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: bit count or bit set && Python3 |
| Date | 2012-10-25 16:16 -0400 |
| References | <mailman.2846.1351176984.27098.python-list@python.org> <a4a3d0f1-b5d8-4f76-a7b7-bda8936761ae@i7g2000pbf.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2863.1351196196.27098.python-list@python.org> (permalink) |
On 10/25/2012 12:13 PM, rusi wrote: > On Oct 25, 7:56 pm, Charles Hixson <charleshi...@earthlink.net> wrote: >> In Python3 is there any good way to count the number of on bits in an >> integer (after an & operation)? >> Alternatively, is there any VERY light-weight implementation of a bit >> set? I'd prefer to use integers, as I'm probably going to need >> thousands of these, if the tests work out. But before I can test, I >> need a decent bit counter. (shift, xor, &, and | are already present >> for integer values, but I also need to count the number of "true" items >> after the logical operation. So if a bitset is the correct approach, >> I'll need it to implement those operations, or their equivalents in >> terms of union and intersection.) >> >> Or do I need to drop into C for this? If I wanted 1000s of fast limited-length bitsets, I would consider using Cython to make an extension class. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
bit count or bit set && Python3 Charles Hixson <charleshixsn@earthlink.net> - 2012-10-25 07:47 -0700
Re: bit count or bit set && Python3 rusi <rustompmody@gmail.com> - 2012-10-25 09:13 -0700
Re: bit count or bit set && Python3 Terry Reedy <tjreedy@udel.edu> - 2012-10-25 16:16 -0400
Re: bit count or bit set && Python3 Christian Gollwitzer <auriocus@gmx.de> - 2012-10-25 19:25 +0200
Re: bit count or bit set && Python3 Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-25 12:19 -0600
Re: bit count or bit set && Python3 casevh@gmail.com - 2012-10-26 08:42 -0700
Re: bit count or bit set && Python3 Charles Hixson <charleshixsn@earthlink.net> - 2012-10-26 09:30 -0700
Re: bit count or bit set && Python3 casevh@gmail.com - 2012-10-26 08:42 -0700
csiph-web