[issue19915] int.bit_at(n) - Accessing a single bit in O(1)

Tim Peters report at bugs.python.org
Sat Dec 7 01:44:47 CET 2013


Tim Peters added the comment:

I'd rather see `i.bits_at(pos, width=1)`, to act like

(i >> pos) & ((1 << width) - 1)

That is, extract the `width` consecutive bits at positions 2**pos through 2**(pos + width - 1) inclusive.

Because Python ints maintain the illusion of having an infinite number of sign bits, I don't think negative `pos` (or `width`) can be assigned a sensible meaning.  Python ints only have "one end".

And, yup, I've often wanted this too!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19915>
_______________________________________


More information about the Python-bugs-list mailing list