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).

  • result is the binary string of the sum, truncated (and left-padded with zeros) to exactly bits digits — i.e. what would actually be stored in a fixed-width register.
  • overflow is True if the true sum needed more than bits digits, False otherwise.

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.