Convert Decimal to Binary in Python Using Recursion

(Last Updated On: 02/12/2022)

Python Program to Convert Decimal to Binary Using Recursion

# Convert Decimal to Binary in Python Using Recursion

def find( decimal_number ):
    if decimal_number == 0:
   	 return 0
    else:
   	 return (decimal_number % 2 + 10 *
   			 find(int(decimal_number // 2)))

# we are taking a number from user as input
# entered value will be converted to int from string
decimal_number=int(input("Enter the decimal number:"))
 
print("the Binary number of ", decimal_number," is ", find(decimal_number))

Output:

Enter the decimal number:24
the Binary number of  24  is  11000

Leave a Reply

Your email address will not be published. Required fields are marked *