How do you convert a list of 0 and 1's into a binary number with base 10?
For example: ([0,0,1,0,0,1]) will give me 9
3 Answers
You can use int function with the second parameter which indicates the base. As, the list is full of numbers, that has to be converted to a string (int accepts only string), so we do map(str, data)
print "".join(map(str, data))
Output
001001
So, it boils down to this
data = [0,0,1,0,0,1]
print int("".join(map(str, data)), 2)
Output
9