Bit length of int or long?

François Pinard pinard at iro.umontreal.ca
Thu May 18 03:26:16 CEST 2000


Dan Schmidt <dfan at harmonixmusic.com> écrit:

> Well, you can always do something like this:

> def bitl(x):
>     assert x >= 0
>     n = 0
>     while x > 256:
>         n = n + 8
>         x = x >> 8
>     while x > 0:
>         n = n + 1
>         x = x >> 1
>     return n

I'm saving these ideas.  Thanks to all.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list