So I am working on a competitive programming problem where you take two numbers base two and base three, and then do some operations on them. I got the code implementing correctly, however it doesn't work with large inputs. For example, when I try to input 10010111011100101101100011011 (base two) and 211010102022001220 (base three). This is because I am inputting them as a regular integer, then converting them to their actual base 10 value.
This is my conversion function (just for bases 2 and 3)
int conv(int base, ll n){
int result = 0;
if(base == 2){
int a = 0;
while(n > 0){
if(n % 2 == 1){
result += pow(2, a);
}
a++;
n /= 10;
}
return result;
}
else if(base == 3){
int a = 0;
while(n > 0){
result += (n%10)%3 * pow(3, a);
a++;
n /= 10;
}
return result;
}
return result;
When I run this function on really small numbers like conv(2, 1010), it works; I get 10 (converting 1010 base 2 into base 10)
However, if I want to take in 10010111011100101101100011011(base 2), my code doesn't seem to work. Is there any other way I can do this?