Python Convert Decimal to Binary or Binary to Decimal
###### Posted by Samath
Last Updated: January 09, 2017

This program converts a decimal to a binary or a binary to a decimal using the Python programming language. The user is provided with a menu to choose to either convert from decimal to binary or binary to decimal, the program then ask the user for a number to convert, then convert that number according the menu choice selected.

```print"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
print" DECIMAL TO BINARY AND BINARY TO DECIMAL CONVERSION"
print"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
print" Press 1 to convert Decimal to Binary"
print" Press 2 to convert Binary to Decimal"
print"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
if x==1:
i=1
s=0
dec=input("Enter decimal to be converted: ")
while dec>0:
rem=dec%2
s=s+(i*rem)
dec=dec/2
i=i*10
print "The binary of the given number is ",s,'.'
else:
bin=raw_input ('Enter binary to be converted: ')
n=len(bin)
res=0
for i in range(1,n+1):
res=res+ int(bin[i-1])*2**(n-i)
print "The decimal of the given binary is ",res,'.'
print"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
raw_input()```

###### Python to Convert Decimal to Binary, Octal and Hexadecimal
gideonna | Apr 13, 2016
###### Decimal to Binary in C++
Samath | Dec 26, 2014
###### Binary to Decimal Conversion in C#
Samath | Jan 10, 2021
###### Convert Roman numerals to decimal using Java
Samath | Jan 17, 2024
###### C++ Convert from Decimal to Octal
Samath | Jan 05, 2017
###### Convert ASCII Character to Hexadecimal and Binary using C++
Samath | Jan 05, 2017
###### SQL Display two digits after decimal point
SceDev | Feb 08, 2024
###### How do you use the BINARY_CHECKSUM function to generate a hash value for a binary data?
PaulAnd | Jun 21, 2024
###### How do you use the BINARY data type to store binary data?
MaryJns | Jul 11, 2024
###### Converting Time To Decimal using C++
Samath | Jan 04, 2017
###### C++ program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer
Samath | Apr 06, 2022
###### C++ program that prompts the user to input five decimal numbers, prints the five decimal numbers, converts each decimal number to the nearest integer, adds the five integers and prints the sum and average of the five integers.
Samath | Apr 06, 2022
###### Binary Search Tree in C++
Samath | Jan 07, 2021
###### How to add and retrieve record in a binary file using C++
Samath | Jan 06, 2021