Number of bits/sizeof int

Scott David Daniels Scott.Daniels at Acm.Org
Sat Jan 31 02:34:14 EST 2009


Jon Clements wrote:
> ... From http://docs.python.org/dev/3.0/whatsnew/3.1.html:
> "The int() type gained a bit_length method that returns the number of
> bits necessary to represent its argument in binary:"
> 
> Any tips on how to get this in 2.5.2 as that's the production version
> I'm stuck with.


Well, what are your arg constraints?  Integers in 0 .. 2**53?
     math.frexp(n)[1]

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list