[issue19915] int.bit_at(n) - Accessing a single bit in O(1)
Tim Peters
report at bugs.python.org
Mon Dec 9 18:06:00 CET 2013
Tim Peters added the comment:
@pitrou, I think usability is a lot more valuable than cross-feature "formal consistency" here. I've been extracting bit fields for decades, and always think of them in terms of "least-significant bit and number of bits". Perhaps the underlying difference is that nobody ever thinks of bit positions as being _between_ bits - instead we always think of "bit i" as being the bit with binary value 2**i. It's more of a math concept than an indexing concept.
For a bit _array_ I'd agree slicing semantics would make more sense. But Python ints have infinite width, and "index 0" is at the rightmost position (not the leftmost position - there is no leftmost position).
I'd also like to avoid the nuisance of having to implement all the goofy slicing possibilities, like non-unit strides and negative strides. Not that they're "goofy" in general - they're goofy in the context of extracting bits from an integer. Again a bit array is a different kind of beast.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19915>
_______________________________________
More information about the Python-bugs-list
mailing list