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 sorted()
Python Program to Print all Prime Numbers in an Interval
Python Program to Convert Two Lists Into a Dictionary
Python Dictionary update()
Python Program to Count the Number of Digits Present In a Number
Python Program to Find Numbers Divisible by Another Number
Python del Statement
Python abs()
Python ord()
Python Program to Multiply Two Matrices
Python String ljust()
Python Program to Get Line Count of a File
Python Function Arguments
Python Program to Find the Sum of Natural Numbers
Python Input, Output and Import
Python Program to Print Output Without a Newline
Python String isalpha()
Python frozenset()
Python Dictionary pop()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python String islower()
Python Inheritance
Python Program to Display the multiplication Table
Python Anonymous / Lambda Function
Python Program to Check Leap Year
How to get current date and time in Python?
Python Global, Local and Nonlocal variables
Python Set update()
Python Statement, Indentation and Comments
Python String swapcase()
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Find LCM