-1

I have an input a=int(1010). I want to find integer equivalence of binary 1010. If I use bin(a) then output will be 1111110010, but I want to get 10.

Lee
  • 169
  • 1
  • 9

1 Answers1

1

You need to tell python, that your integer input is in binary. You can either parse a string with a defined base, or ad a 0b-prefix to your code constants.

a = int("1010", base=2)
a = 0b1010
print(a)      # result: 10
print(bin(a)) # result: 1010
Jeanot Zubler
  • 979
  • 2
  • 18