0

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
1
  • is the "0b" in the string the substring that tells u that it's binary? Commented Feb 2, 2011 at 17:37

1 Answer 1

6
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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.