Problem 227
Add Binary
Easy · 10 pts · String, Math, Bit Manipulation
Problem
You are given two binary numbers A and B as strings of 0's and 1's. They can be up to 10,000 digits long, too long for built-in integer types. Print their sum, also in binary, without leading zeros. Add them like decimal numbers on paper, but in base 2: start from the rightmost digits, add the two digits and the carry, write sum mod 2, and carry sum / 2 to the next position. Remember the final carry.
Input
Two lines: binary strings A and B (no leading zeros unless the number is 0).
Output
Print the sum in binary.
Constraints
1 <= length of A, B <= 10000
Example input
11 1
Example output
100
Explanation
11 in binary is 3 and 1 is 1. Adding from the right: 1 + 1 = 10 (write 0, carry 1), then 1 + carry 1 = 10 (write 0, carry 1), then the final carry 1. The result is 100, which is 4.