1int pow(int base, int exp)
2 {
3 if(exp < 0)
4 return -1;
5
6 int result = 1;
7 while (exp)
8 {
9 if (exp & 1)
10 result *= base;
11 exp >>= 1;
12 base *= base;
13 }
14
15 return result;
16 }
17