In this Python example we will convert a decimal number into its corresponding binary form.

E.g 15 -> 1111

decimal to binary

Recommended:

Convert Decimal to Binary in Python without bin()

In this method, we are taking a decimal number as input and dividing it by 2 until the number reduces to 0. All the remainder is concatenated together in bottom-up manner.

Output

Convert Decimal to Binary in Python using Recursion

In this python program, we are using recursion to convert the decimal into binary number. On each recursive call we are passing the quotient (dividend/2) as the parameter.

Since it is a tail recursion, the remainder will be printed from last-remainder to first-remainder (bottom up manner ).

Output

Convert Decimal to Binary in Python using bin()

Output

If you have any doubts then comment below.

Leave a Reply

Close Menu