Sep-11-2022, 05:01 PM
Convert it to an int?
If this is a homework assignment, and you need to do the addition using the binary string, 1+1 = 0, carry the 1. You don't have a carry in you code.
I think it would also be easer working left to right instead of right to left. I would start by reversing the string "1010" to "0101", then I would do the addition, and finally I would reverse the string back.
If this is a homework assignment, and you need to do the addition using the binary string, 1+1 = 0, carry the 1. You don't have a carry in you code.
I think it would also be easer working left to right instead of right to left. I would start by reversing the string "1010" to "0101", then I would do the addition, and finally I would reverse the string back.
Output:1010 + 1
Reverse the strings
0101
+1
Do the addition
0+1 = 1
1+_ = 1
0+_ = 0
1+_ = 1
1101
Reverse the result
1011
If there is a carryOutput:1010 + 10
Reverse the strings
0101
+01
Do the addition
0+0 = 0
1+1 = 0, carry = 1
0+_+carry = 1
1+_ = 1
0011
Reverse the result
1100