I am writing a program where the input data (in binary) is split into half and convert to integer to perform some calculation. So I:
Accept binary input and store as "String"
Split string (note: to be treated as binary) into half and convert to int and store in x and y
So far i have written step 1.
int main() {
string input;
cout << "Enter data:";
getline(cin, input);
int n = input.size();
int n1 = n/2;
string a, b;
a = input.substr(0,n1);
b = input.substr(n1);
cout << "a: " << a;
cout << "b: " << b;
}
Would like to know how to achieve step 2. Thanks in advance.
atoi"[...] takes an optional initial plus or minus sign followed by as many base-10 digits [...]". As to the question - we don't solve homeworks here. Read this: en.wikipedia.org/wiki/Binary_number#Decimal and then implement. It is one of the most basic algorithms in CS.