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>

<p>The solution depends on your way to enumerate the features. if you enumerate your features from 0 to 63 it would be something like this:</p>

<pre><code>import math

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

def test_feature(data, i):
        block = math.floor(i/8)
        pos = i % 8

        if data[block][pos] == '1':
                return True

        return False

print(testdata)
print(test_feature(testdata, 0))
print(test_feature(testdata, 3))
print(test_feature(testdata, 8))
print(test_feature(testdata, 17))
print(test_feature(testdata, 33))
print(test_feature(testdata, 63))
</code></pre>

<p>However, you can easily adjust this method to match other enumerations.</p>

python python-2.7