89DEVs

Python: How to convert binary to decimal?

How to convert binary to decimal in Python?

To convert a binary to a decimal in Python, use the int() function and set the base to 2 to convert it to an integer. Then use the float() function to convert the integer to a float value.

convert binary to decimal

To convert the binary to decimal, use the float() and int() functions as shown below. # convert binary to decimal myBinary = '101' myDecimal = float(int(myBinary, 2)) print(myDecimal) The int() function with the second argument 2 converts the binary representation to an integer value. Then the integer is converted to a float value by the float() function. Finally, the decimal value is printed. 5.0

                
        

Summary


Click to jump to section