Determining combination of bits

Sean Berry sean at
Mon Nov 8 21:33:48 CET 2004

Just to set everyone's mind at ease... I haven't had a homework assignment 
for about four years now.

I am using two database tables.  One will have some options and a code 
(power of 2).

Then, someone will check off checkboxes and submit.  The number will be 
added and saved in a cookie.  Then, later, I want to be able to redisplay 
their choices by reading the value from the cookie.

I expect the values will get no bigger than 2^32  = 4294967296.  Is this 
getting too big???

"Terry Reedy" <tjreedy at> wrote in message 
news:mailman.6124.1099945664.5135.python-list at
> "Sean Berry" <sean at> wrote in message 
> news:x3Qjd.121786$hj.41260 at fed1read07...
>> and I am given some numbers, say 22, 25, and 9.  I want to determine the 
>> keys, powers of 2, that comprise the number.
>> How do I get these keys?
> if n%2: print 'has a positive one bit'
> n//2 == n>>1 deletes that bit
> keep track of divisions/shifts and stop when n == 0
> Terry J. Reedy

More information about the Python-list mailing list