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 Sort a Dictionary by Value
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
APIs in Node.js vs Python - A Comparison
Python eval()
Python Program to Iterate Over Dictionaries Using for Loop
Python Input, Output and Import
Python String translate()
Python sleep()
Python @property decorator
Python Program to Split a List Into Evenly Sized Chunks
Python bytes()
Python Program to Append to a File
Python Dictionary
Python String endswith()
Python Package
Python Program to Get a Substring of a String
Python hex()
Python Program to Find the Square Root
Python Tuple
Python staticmethod()
Python Program to Check if a Number is Odd or Even
Python Program to Check If a List is Empty
Python String format_map()
Python Program to Print all Prime Numbers in an Interval
Python hasattr()
Python Program to Find the Factors of a Number
Python frozenset()
Binary Numbers in Java
Python String startswith()
Python Matrices and NumPy Arrays
Python Set remove()
Python Program to Check Whether a String is Palindrome or Not