Add Binary
Given two binary strings a and b, return their sum as a binary string.
A binary string contains only the characters 0 and 1.
Example 1
Input
a = "11" b = "1"
Output
"100"
Explanation
11
+ 01
----
100
Example 2
Input
a = "1010" b = "1011"
Output
"10101"
Explanation
1010
+ 1011
------
10101
Constraints
Hints:
Hint 1
Start adding from the rightmost digits, just like normal decimal addition.
Hint 2
Keep a carry variable.
For each position:
sum = bitA + bitB + carry
The current binary digit is:
sum % 2
and the new carry is:
sum / 2
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 22, 2026
Last updated
Aug 23, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output