Sign in to follow this  

Get exponent from number and base?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by load_bitmap_file
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


Log returns base-10 logarithm?

Share this post


Link to post
Share on other sites
Quote:
Original post by Raeldor
Log returns base-10 logarithm?


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

Share this post


Link to post
Share on other sites
Quote:
Original post by chaosgame
Quote:
Original post by Raeldor
Log 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 this post


Link to post
Share on other sites
Quote:
Original post by Raeldor
Is this one of these mathematical mysteries like PI? :P

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

CM

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this