Let\'s a=109 or 1101101 in binary. How do I iterate over bits of this number, eg: [64, 32, 8, 4, 1]
a=109
1101101
[64, 32, 8, 4, 1]
Example one-line solution:
[1 << bit for bit in xrange(bitfield.bit_length()) if bitfield & (1 << bit)]
Or:
[bit for bit in (1 << n for n in xrange(bitfield.bit_length())) if bitfield & bit]
Notes: