How to locate the bit in bits string?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Apr 29 00:23:08 EDT 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)
12
>>> sys.getsizeof('1100011')
31


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



-- 
Steven



More information about the Python-list mailing list