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 Program to Iterate Over Dictionaries Using for Loop
Python frozenset()
Python Set issubset()
Python List Comprehension
Python complex()
Python *args and **kwargs
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python String rpartition()
Python Tuple
Python super()
Python Namespace and Scope
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Program to Get File Creation and Modification Date
Python Program to Find All File with .txt Extension Present Inside a Directory
Python ord()
Python Program to Check Leap Year
Python Set issuperset()
Python Program to Convert Celsius To Fahrenheit
Python str()
Python String replace()
Python max()
Python Data Structures and Algorithms - Benjamin Baka
Python String ljust()
Python Program to Create a Countdown Timer
Python Program to Get the Full Path of the Current Working Directory
Python Variables, Constants and Literals
Python String rindex()
Python Program to Find the Factors of a Number
Python Program to Measure the Elapsed Time in Python
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Intelligent Projects Using Python - Santanu Pattanayak
Python String index()