Dcoder icon

Binary Operations @ Dcoder

By Lochard | As a newbie programmer | 16 Aug 2023


Problem: You will be given two numbers, a and b, in their binary form. You need to print their sum and their product in binary.

Input: Two strings separated by space representing the binary values of a and b.

Output: Print their sum(a+b) in the first line.

Print their product(a*b) in the second line.

Constraints: 1 ≤ string.length ≤ 16

Sample Input: 101 10

Sample Output: 

111

1010

a, b = map(lambda s: int(s, 2), input().split())
print(bin(a + b)[2:])
print(bin(a * b)[2:])

How do you rate this article?

2


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.