


In this program, we are using a in-built function bin() to convert the decimal number to binary. The function divideBy2 takes an argument that is a decimal number and repeatedly divides. Python program to convert decimal number to binary using bin() function The Python code in ActiveCode 1 implements the Divide by 2 algorithm. If you wanted to convert the number 21 into binary, you start out with an empty table like. Number = int(input("Enter any decimal number: "))Ģ. Converting numbers back the other way isnt it much more difficult. This function takes the decimal number as an input parameter and converts it into an equivalent binary number.

In this program we have defined a function decimalToBinary() for the conversion. Decimal to Binary conversion using recursive function We will see two Python programs, first program does the conversion using a user defined function and in the second program we are using a in-built function bin() for the decimal to binary conversion. In this post, we will see programs to convert decimal number to an equivalent binary number.
