In this post, we will write a Python 3 program to convert decimal number to binary
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#www.python-examples.com import math num=int(input("Enter a Number : ")) rem="" while num>=1: rem+=str(num%2) num=math.floor(num/2) binary="" for i in range(len(rem)-1,-1,-1): binary = binary + rem[i] print("The Binary format for given number is {0}".format(binary)) |
Output: