Python By Example

Convert decimal to binary

by Jiffin Joachim Gomez on 24th February 2017

The program asks the user to input the decimal number, In Python we have built in functions to convert decimal to binary, just use bin() function to convert any number. So we don't have to worry about the mathematics behind how to convert decimal numbers to binary.

#Getting input from the user
dec = int(input("Enter the decimal value: "))
print("The decimal value of",dec,"is:",bin(dec)[2:],"in binary.")
Enter the decimal value: 14
The decimal value of 14 is: 1110 in binary.

Post a comment


Nothing the first to share wisdom.