This is a simple program in python to find the binary equivalent of any given decimal base number. This basically takes input as a decimal base number and coverts it into binary base and prints it.
if(x==0): #The Binary equivalent of decimal 0 is 0
b=b+str(x%2) #Typecasting an Integer to String
b=b[::-1] #Reverse the String
firstly input is taken from the keyboard and stored in inp variable. Then this variable is passed to bin() from where operations are performed and the result is then concatenated in a null string. The concatenation is done by type casting the integer to string i.e. str(x%2) and finally the string b is reversed and then displayed in the console.
If helpful, share the code 🙂
Latest posts by Bikash Panda (see all)
- OSMC on Raspberry PI with Setup and Control using Android App - July 7, 2017
- DHT12 Interfacing with Raspberry Pi using Pi4J - June 19, 2017
- Send data using MQTT from Raspberry Pi with JAVA - June 12, 2017