Binary Adder with Overflow Detection
Write a function binary_add(a, b, bits) that adds two binary strings a and b (each already padded to bits digits) and returns a tuple (result, overflow).
resultis the binary string of the sum, truncated (and left-padded with zeros) to exactlybitsdigits — i.e. what would actually be stored in a fixed-width register.overflowisTrueif the true sum needed more thanbitsdigits,Falseotherwise.
Read one line of input at a time: a, then b, then bits (an integer). Print result and overflow separated by a space.
Example: input 0111, 0011, 4 → the sum is 1010 which fits in 4 bits, so output is 1010 False.
main.py
Loading editor…
Console
Run your code to see output here.