Bit length of int or long?

François Pinard pinard at iro.umontreal.ca
Wed May 17 21:26:16 EDT 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