how to get the thighest bit position in big integers?

Mensanator mensanator at aol.com
Wed Oct 29 17:43:13 EDT 2008


On Oct 29, 4:16 pm, Glenn Linderman <v+pyt... at g.nevcal.com> wrote:
> On approximately 10/29/2008 11:51 AM, came the following characters from
> the keyboard of Mensanator:
>
> > or in 2.6
>
> > print 'highest bit position: %d' % (len(bin(3328)[2:])-1)
>
> > highest bit position: 11
>
> This works, but where is it documented?  

Good question. Now that I think about it, I believe I learned of
it here, never saw it in the docs.

> Searching the Python 2.6 docs
> for bin found lots of things that start with bin, but none of them were
> bin.  Searching the builtins page manual didn't find it.  Is this a bug
> in the documentation?

Well ,it's mentioned in "What's new in Python 2.6":
<quote>
Python 3.0 adds several new built-in functions
and change the semantics of some existing built-ins.
Entirely new functions such as bin() have simply
been added to Python 2.6, but existing built-ins
haven’t been changed;
</quote>

You would think when you add a new function, you would
also add it's documentation, but maybe that was an
oversight. I don't have 3.0, but maybe it can be found
in that set of docs.

>
> --
> Glenn --http://nevcal.com/
> ===========================
> A protocol is complete when there is nothing left to remove.
> -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking




More information about the Python-list mailing list