Bit length of int or long?
Michael Hudson
mwh21 at cam.ac.uk
Thu May 18 04:16:42 EDT 2000
Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:
> How about...
>
> import math
>
>
> def bitlen(x):
> assert x > 0
> return math.floor (math.log10(x) / math.log10(2) ) + 1
>
Because:
>>> def bitlen(x):
... assert x > 0
... return math.floor (math.log10(x) / math.log10(2) ) + 1
...
>>> bitlen(2**10000L)
inf
(which surprised me; I'm sure that used to raise an exception - has
this changed recently?)
Cheers,
M.
--
how am I expected to quit smoking if I have to deal with NT
every day -- Ben Raia
More information about the Python-list
mailing list