0

I want to take this string '01101011' as an 0b01101011 integer in Python.I couldn't find any method to do that.I tried:

a=a+"0b"
a=int(a)

But is has no use.Can you help me guys?

1
  • 1
    Try a='01101011', then a = int(a, 2) Commented Nov 23, 2020 at 7:49

1 Answer 1

1

String to bitstring: Convert the string to integer then to binarystring.

>>> a_str = '101011'
>>> a_bit_str = bin(int('101011',2))
>>> a_bit_str
'0b101011'

String to Integer: If you just want to convert string to integer

>>> int(a_str,2)
43
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.