Sign in to follow this  
Raeldor

Get exponent from number and base?

Recommended Posts

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

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