954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

binary addition

So essentially I'm prompting the user for two binary numbers. How can I add these together? I don't know how to get the 0b in front the the original input. If there is an easier way to do it, please let me know.

#Prompt the user for two binary numbers
bin1 = raw_input("Please enter a binary number: ")
bin2 = raw_input("Please enter another binary number: ")

binstr1 = str(bin1)
binstr2 = str(bin2)


#Check to verify that the user input two binary numbers
while '1' and '0' in binstr1, binstr1:
print str(binstr1)
else:
binstr1 = raw_input("You did not enter a binary number, Please try again: ")

This is what I have so far, but it doesn't work and have hit a wall.

NumeroUno123
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

use the inbuilt function bin to convert decimal numbers to binary

britanicus
Newbie Poster
19 posts since May 2010
Reputation Points: 11
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: