How to convert binary to decimal in Python

3 Answers

0 votes
binary = 1101

decimal = int(str(binary), 2)

print(decimal)



'''
run:

13

'''

 



answered Nov 2, 2021 by avibootz
0 votes
binary = "00101101"

decimal = int(binary, 2)

print(decimal)



'''
run:

45

'''

 



answered Nov 2, 2021 by avibootz
0 votes
binary = "00101101"

decimal = 0
for digit in binary:
    decimal = decimal * 2 + int(digit)

print(decimal)



'''
run:

45

'''

 



answered Nov 2, 2021 by avibootz

Related questions

2 answers 148 views
1 answer 144 views
1 answer 174 views
2 answers 194 views
1 answer 135 views
...