[issue3439] create a numbits() method for int and long types

Zooko O'Whielacronx report at bugs.python.org
Tue Jun 22 00:04:05 CEST 2010


Zooko O'Whielacronx <zooko at zooko.com> added the comment:

There is a small mistake in the docs:

def bit_length(x):
    'Number of bits necessary to represent self in binary.'
    s = bin(x)          # binary representation:  bin(-37) --> '-0b100101'
    s = s.lstrip('-0b') # remove leading zeros and minus sign
    return len(s)       # len('100101') --> 6

is probably supposed to be:

def bit_length(x):
    'Number of bits necessary to represent x in binary.'
    s = bin(x)          # binary representation:  bin(-37) --> '-0b100101'
    s = s.lstrip('-0b') # remove leading zeros and minus sign
    return len(s)       # len('100101') --> 6

----------
nosy: +zooko

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3439>
_______________________________________


More information about the Python-bugs-list mailing list