I'm building my own string class and I'm trying to use this function to convert a numerical string to an integer:
int String::convertToInt() const {
int exp = length() - 1;
int result = 0;
for(int i = 0; i < length(); ++i) {
result += (charAt(i) - '0') * (10 ^ exp);
--exp;
}
return result;
}
Something isn't working right, but I can't pick out what it is. When I try to convert "49" to an int, it converts it to 134.