I need to sum 2 binary numbers (max len 8 and min 1) using only selective structures (if, elif, else) and loops (for, while).
You need to know in the binary sum:
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0 (with carry 1)
The result must be the sum of these two numbers. Also, show the partial results that are generated by adding two digits and carrying
I know you could easily do this, but the idea is use only selective structure and loops.
a = input("first binary: ")
b = input("second binary: ")
c = bin(int(a,2) + int(b,2))
OUTPUT example:
sum:
11001011
10001011
=========
101010110
Partial results:
digit = 0 Carry = 1
digit = 1 Carry = 1
digit = 1 Carry = 0
digit = 0 Carry = 1
digit = 1 Carry = 0
digit = 0 Carry = 0
digit = 1 Carry = 0
digit = 0 Carry = 1
This question is different to the others made, because none of the others answer just using selective and repetitive structures