+ 1
Add binary as string
I want to input Binary of two numbers and want to get their sum as int. Example : input : 1011 , 1010 output: 101 expected output:Â 10101 What is wrong with my code ? code link : https://www.sololearn.com/compiler-playground/cm4RfauB0yXn
5 Answers
+ 2
correct link
https://code.sololearn.com/cm4RfauB0yXn/?ref=app
+ 2
Problem is the way you use stoi function - you are parsing the input strings as decimal numbers, not binary.
Just review stoi function syntax.
+ 1
because int 1011 is one thousand .. and not 0b1011
//c = c >> 1;
//d = d >> 1;
c = c / 10;
d = d / 10;
0
Emerson Prado Thanks bro đ
I got it !
- 2
Whaaa I just started coding