2

I want to convert a string consists of binary digits and convert that string into a binary number.

suppose, my input is "01001", this is in string format, i want to convert this to binary number format to perform various bit wise operations on that.

  • 2
    I am pretty sure there are plenty of answer to this question all around SO. Did you try searching a little? – Paulo Bu Feb 19 '14 at 13:20

1 Answers1

2

You can convert the number to an int and do bitwise operations, like this

my_int = int("01001", 2)
print my_int & 1   # 1
print my_int & 8   # 8
print my_int & 16  # 0
thefourtheye
  • 233,700
  • 52
  • 457
  • 497