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


Groups > comp.lang.python > #32142

Re: bit count or bit set && Python3

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: bit count or bit set && Python3
Date 2012-10-25 17:24 +0100
References <5089511E.4090009@earthlink.net>
Newsgroups comp.lang.python
Message-ID <mailman.2851.1351182149.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 25/10/2012 15:47, Charles Hixson 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 needed bitarray and bitstring are available on pypi.

-- 
Cheers.

Mark Lawrence.

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


Thread

Re: bit count or bit set && Python3 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-25 17:24 +0100

csiph-web