# Get exponent from number and base?

This topic is 4983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there a way to get an exponent from a number and a base. For example, passing 32 and 2 would result in 5 because 2 to the power of 5=32. Thanks

##### Share on other sites
this works it seems

#include <iostream>
#include <math.h>
using namespace std;

int main(){

int tot = //number you want to find exponent of
int curr = 0; //keeps track of values
int x;
for(x = 0; curr <= tot; x++){
curr += pow(2,x);
}
x = x - 1;
cout << x << endl;

}

##### Share on other sites
Simple algebra: log(x)/log(y) or ln(x)/ln(y) if you'd prefer :P

So your example would be log(32)/log(2) = 5

##### Share on other sites
Quote:
 Original post by load_bitmap_fileSimple algebra: log(x)/log(y) or ln(x)/ln(y) if you'd prefer :PSo your example would be log(32)/log(2) = 5

Log returns base-10 logarithm?

##### Share on other sites
Quote:
 Original post by RaeldorLog returns base-10 logarithm?

Doesn't matter, as long as you do log(x)/log(y), it will work.

##### Share on other sites
Quote:
Original post by chaosgame
Quote:
 Original post by RaeldorLog returns base-10 logarithm?

Doesn't matter, as long as you do log(x)/log(y), it will work.

Is this one of these mathematical mysteries like PI? :P

##### Share on other sites
Quote:
 Original post by RaeldorIs this one of these mathematical mysteries like PI? :P

No. In fact, it's pretty trivial to prove if you try.

CM

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015827
×