Tagged Questions
0
votes
0answers
75 views
Bit array not working as fast as expected [closed]
I recently downloaded the bitarray module from here, for a faster prime sieve, but the results are dismal.
from bitarray import bitarray
from numpy import ones
from timeit import timeit
def ...
4
votes
1answer
100 views
Bitwise Flag code for Python
I am looking for feedback on this compact Python API for defining bitwise flags and setting/manipulating them.
Under the hood, FlagType extends int and all operations are true bitwise, so there is ...
1
vote
1answer
103 views
What specific optimizations can be made to this BitArray class, and how can they be implemented?
Here is the current code for the BitArray class needing optimization (implemented on big integers):
import itertools
################################################################################
...
3
votes
4answers
305 views
Counting the number of bits of a positive integer
How can I improve this code for counting the number of bits of a positive integer n in Python?
def bitcount(n):
a = 1
while 1<<a <= n:
a <<= 1
s = 0
while ...