Message205421
For many numeric algorithms it's useful to be able to read individual bits at a location in an integer. Currently there is no efficient way to do this. The following function is the closest to this:
def bit_at(i, n): return (i>>n)&1
However in computing the intermediate result i>>n we must spend O(b-n) time at least (where b is n.bit_length()). It should be possible to read bits in O(1) time. Adding int.bit_at(n) would complement int.bit_length().
I would suggest making the semantics of i.bit_at(n) the same as (i>>n)&1. Although the exact meaning when i is negative should be considered.
Real world uses of bit_at include binary exponentiation and bit counting algorithms. |
|
Date |
User |
Action |
Args |
2013-12-07 00:27:06 | anon | set | recipients:
+ anon |
2013-12-07 00:27:06 | anon | set | messageid: <1386376026.32.0.661343465084.issue19915@psf.upfronthosting.co.za> |
2013-12-07 00:27:06 | anon | link | issue19915 messages |
2013-12-07 00:27:05 | anon | create | |
|