In this program, you will learn to convert decimal number to binary using recursive function.
o understand this example, you should have the knowledge of the following Python programming topics:
Decimal number is converted into binary by dividing the number successively by 2 and printing the remainder in reverse order.

Source Code
# Function to print binary number using recursion def convertToBinary(n): if n > 1: convertToBinary(n//2) print(n % 2,end = '') # decimal number dec = 34 convertToBinary(dec) print()
Output
100010
You can change the variable dec in the above program and run it to test out for other values.
This program works only for whole numbers. It doesn’t work for real numbers having fractional values such as: 25.5, 45.64 and so on. We encourage you to create Python program that converts decimal numbers to binary for all real numbers on your own.
Related posts:
Python String isdecimal()
Python hash()
Python Program to Check If a String Is a Number (Float)
Python String ljust()
Python Program to Print Hello world!
Python Program to Check If Two Strings are Anagram
Python dir()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Capitalize the First Character of a String
Python Program to Iterate Through Two Lists in Parallel
Python Directory and Files Management
Python Program to Represent enum
Python Program to Get the File Name From the File Path
Python id()
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Concatenate Two Lists
Python Set issubset()
Python Program to Find the Sum of Natural Numbers
Python Program to Check If a List is Empty
Python min()
Python tuple()
Python String find()
Python List sort()
Python Dictionary pop()
Python String isupper()
Python Program to Count the Number of Digits Present In a Number
Python list()
Python format()
Python Variables, Constants and Literals
Python Program to Shuffle Deck of Cards
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Differentiate Between del, remove, and pop on a List