This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author anon
Recipients anon
Date 2013-12-07.00:27:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:06anonsetrecipients: + anon
2013-12-07 00:27:06anonsetmessageid: <>
2013-12-07 00:27:06anonlinkissue19915 messages
2013-12-07 00:27:05anoncreate