To convert a number from base 2 to base 10 in Python, we can use the int()
function which takes two arguments - the first argument is the string representation of the number and the second argument is the base of the number.
Here's an example:
main.py72 chars4 lines
In this example, we have a binary number '1010'. We pass this number along with the base 2 as arguments to the int()
function, which converts the binary number to its decimal equivalent. We then print out the decimal number which is 10.
So, the output of the above code will be:
main.py3 chars2 lines
gistlibby LogSnag