result
to store the binary sum.i
and j
to point to the last characters of strings a
and b
respectively.carry
to 0 to keep track of the carry from the addition of two bits.i
or j
is greater than or equal to 0 or carry
is not 0:
a. Compute the sum of carry
and the last bits of a
and b
if i
or j
is valid.
b. Update carry
to be the sum divided by 2 (to represent the carry in binary addition).
c. Append the sum modulo 2 to the result
string (to represent the bit value).
d. Decrement i
and j
.result
string to get the final binary sum.result
string.