Program to add two binary numbers using bin function
Program to add two binary numbers using bin function
Program to add two binary numbers using bin function.
A program that combines two binary numbers
In the following program, we use two built-in functions int () and bin ().
The int () function takes into account the source value provided by the given string, in the following example we convert the string (which is a binary value) to an integer, so we set the source value to 2 (binary numbers have base 2, decimals have a base value of 10).
After converting strings to integer values. we add them and the result is converted to binary number using bin () function.
Python code:
a = int(input('enter first number'))
b = int(input('enter second number'))
sum = bin(a+b)
print(sum)
Output:
enter first number 67
enter second number 54
0b1111001
Recommended Post:
Python Program to check vowel or Consonant
Program to check character is alphabet or not in Python
Python to check whether the year is leap or not
Python to check if number is Positive, Negative or 0
Python Program to solve Quadratic equation
Program to generate Random numbers in Python
Program to swap two numbers in Python
Program to Add two numbers in Python
Python to convert decimal to binary, octal and hexadecimal
Python Program to find large number among three numbers