Program for adding two binary numbers In this tutorial, We have used two built-in functions
bin(). The int() function converts the given string into an integer number considering the provided base value.
When two numbers are added together in denary, we take the first number, add the second number to it and get an answer. For example, 1 + 2 = 3. When we add two binary numbers together the process is different.
# decimal value 1
num1 = '00001'
# decimal value 17
num2 = '10001'
# sum - decimal value 18
# binary value 10010
sum = bin(int(num1,2) + int(num2,2))
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.