Write a program in Python to add two binary numbers and output the sum.

In Python, we can add two binary numbers using the following syntax

where binary_1 and binary_2 are two binary numbers in string format.

int() method in python convert the string into integer of the specified base. If we pass 2 as the second parameter to int() then we get the binary number as the return result (Binary have a base value of 2 whereas Decimals have base value 10).

After converting the string into binary, we add them.

Since the addition in Python returns an integer of base 10 (decimal), so we have to convert it to base 2 (binary) using bin() method.

Let’s see an example of adding two binary numbers in Python.

Output

Hope the program is easy for you. If you have any suggestions or doubts then please comment below.

Leave a Reply