iterating bit-by-bit across int?

Matthew Wilson mwilson at
Thu Oct 23 20:54:54 CEST 2003

I'm playing around with genetic algorithms and I want to write a
function that mutates an integer by iterating across the bits, and about
1 in 10 times, it should switch a zero to a one, or a one to a zero.

I'm not sure how many bits are inside a python integer.  The library
reference says at least 32.

I'm thinking about writing a function that eats integers and poops out
lists of bools; and then I can iterate through that, and change values
in there.  But before I do that, does anyone have a better idea?

More information about the Python-list mailing list