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
.
Asked
Active
Viewed 37 times
-1

Lee
- 169
- 1
- 9
-
1`a=int(1010, base=2)` – Jeanot Zubler Oct 05 '22 at 12:42
-
`int() can't convert non-string with explicit base` this error appears when I use `a=int(1010, base=2)` – Lee Oct 05 '22 at 12:44
1 Answers
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