How would I convert a binary string to a decimal number? I am taking the binary out of a list of values, and need to then convert it to decimal format.
ex. x=["0b000101"] needs to become x= [5]
Is this Possible?
SilentGhost
322k67 gold badges312 silver badges294 bronze badges
asked Feb 2, 2011 at 17:34
Kyra Elizabeth
511 silver badge4 bronze badges
-
is the "0b" in the string the substring that tells u that it's binary?Sören– Sören2011年02月02日 17:37:24 +00:00Commented Feb 2, 2011 at 17:37
1 Answer 1
In [66]: x
Out[66]: ['0b000101']
In [67]: [int(elt,base=2) for elt in x]
Out[67]: [5]
answered Feb 2, 2011 at 17:36
unutbu
887k197 gold badges1.9k silver badges1.7k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py