Add Binary
Practice this coding question on Coding Gurukul.
Problem statement
Two telemetry devices store their counters as binary text. The receiver must combine these counters without assuming that either value fits into a machine integer, and then send the total back in the same binary format. Your task Given two binary strings a and b, add their represented nonnegative integers and print the binary representation of the sum. Important details Process carries correctly across runs of ones. The strings may have different lengths. The answer must have no leading zeroes unless it is exactly 0; do not concatenate the strings or add their decimal spellings. Worked example The strings 1011 and 110 represent 11 and 6. Their total is 17, whose binary representation is 10001.
Input format
Two lines containing a and b.
Output format
Print the binary sum.
Constraints
1 <= lengths <= 10000; strings contain only 0 and 1 and have no leading zeroes except the value 0.
Sample input
1011 110
Sample output
10001
Sign in to run or submit a solution in C++, Java or Python.