How to locate the bit in bits string?

Steven D'Aprano steven at
Wed Apr 29 06:23:08 CEST 2009

On Wed, 29 Apr 2009 00:36:56 +1000, Li Wang wrote:

> Although bin(99)[4] could be used to locate it, this transform cost too
> much memory (99 only needs 2Bytes, while string '1100011' needs 7Bytes).

This is Python, not C. Your figures are completely wrong.

>>> sys.getsizeof(99)
>>> sys.getsizeof('1100011')

Everything in Python is an object. If you're expecting C performance for 
bit-twiddling operations, you aren't going to get it.


More information about the Python-list mailing list