I need to calcuate something to the log2. Unfortunatly, my caculator(a scientific calculator) does not have that function.
How do I aproximate it with other keys(I have LOG and LN, as well as the standred set).
I need to calcuate something to the log2. Unfortunatly, my caculator(a scientific calculator) does not have that function.
How do I aproximate it with other keys(I have LOG and LN, as well as the standred set).
You could always use the Taylor series for logs
Use the change of base formula. log[sub]2/sub = ln(x)/ln(2).
Do you mean a base 2 logarithm? If so, log2(x)=log(x) / log(2), where the logs on the right hand side are any base you like (as long as you use the same base for both).
Basically, ln(x+1) = x - (x^2)/2 + (x^3)/3 - … with the domain [-1,1].
So, ln2 = 1- 1/2 + 1/3 -(1/4)…
Of course that’s the natural log. I’m not sure what base you want.
Oops. I think I misread, you want to know how to find something in base 2. Ignore my post.
I constantly find myself doing math in my head, even in this age of calculator (even though a calculator watch was my preferred timepiece until 5-7 years ago).
Though the the answer given earlier, which can be generalized as:
log[sub]2/sub = log[sub]x/sub/ log[sub]x/sub
(where log[sub]a/sub is the log of B in the base a)
is exactly accurate, it overlooks a fact I use almost daily: in quick approximations, **log[sub]10/sub is a wonderfully convenient 0.3 (actually 0.3010299957… but that’s an error of only 0.003421 or ~1/3 of a percent, which I can usually live with. Besides I know the correct value, so I can correct for it in my head)
Okay, so I was a math geek as a kid and never outgrew it. I wouldn’t advise making anything of that: I was also a martial arts geek.
Make that: log[sub]10/sub is a wonderfully convenient 0.3 (actually 0.3010299957…)
I never claimed to be a UBB code geek.
Or try the handy calculator at:
http://www.1728.com/logrithm.htm
It will compute logs in ANY base.
The OP’s question has been well answered (by ultrafilter and others), but I thought I’d show the derivation of this formula.
log[sub]2/sub is by definition y, where y is the exponent so that 2[sup]y[/sup] = x.
Take logs of both sides of this equation (ln is most natural, heh heh, but “common” logs will do just as well):
ln 2[sup]y[/sup] = ln x
Then y ln 2 = ln x by one of the magical properties of logarithms.
Finally, solving for y yields y = ln x / ln 2.
This gives the exact answer, not an approximation (except insofar as your calculator can only give you so many digits), and is easy enough to do that most calculator manufacturers don’t see the point of including a special key for logs to other bases.
If you have a TI-83 or similar, you can write a very simple program to do this for you, using the “change of base formula” mentioned above:
:Disp "LOGARITHM"
:Input "BASE ",B
:Input "OF ",X
:Disp ln(X)/ln(B)
And that’s less than 60 bytes.
If you have access to a linux box, it likely has bc installed. Be sure to invoke it as “bc -l” to preload the math library.
the function l() is natural log, so to get log (base 2) of 64:
enter
l(64)/l(2)
and it will say
6.000000000000
Thanks for the help. I appreciate it.