Parsing of list of bits in python
<p>I have a list of 64 bits.</p>

<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>

<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>

<p>Is there any way were i can check the bit and just return its associated feature if it is 1.</p>

<p><code>Input : 1111111</code></p>

<p><code>Output: If all bits are one then I need to print all eight features masked in it.</code></p>

<pre><code>def f0(): print "executing feature0"
def f1(): print "executing feature1"
def f2(): print "executing feature2"
def f3(): print "executing feature3"
def f4(): print "executing feature4"
def f5(): print "executing feature5"
def f6(): print "executing feature6"
def f7(): print "executing feature7"


def run_features(mask):
    for index, bit in (enumerate(mask[::-1])):
        if bit == '1':
            features[index]()

bits = [
    '11111111', '11111111', '10001111', '11111110',
    '11011011', '11111111', '01011011', '10000111'
]

features = [
    f0, f1, f2, f3, f4, f5, f6, f7
]

for mask in bits:
    run_features(mask)
    print '-' * 80
</code></pre>

python python-2.7