It turns out that the number 1 reason people visit this blog is to calculate log base 2 of an integer. So here is log
2 of 1 through 10, to 16 digits precision:
log
2(1) = 0
log
2(2) = 1
log
2(3) = 1.584962500721156
log
2(4) = 2
log
2(5) = 2.321928094887362
log
2(6) = 2.584962500721156
log
2(7) = 2.807354922057604
log
2(8) = 3
log
2(9) = 3.169925001442312
log
2(10) = 3.321928094887362
Note that log
2(
x) is defined for any
x greater than zero. If you have a calculator than computes the natural logarithm (often denoted ln), then you can calculate log
2(
x) = ln(
x)/ln(
2). The same thing works with log base 10, i.e. log
2(
x) = log
10(
x)/log
10(
2).
But what does it mean?
log
2(
x) means the power you have to raise 2 in order to get
x. For example, 2
2 = 4, so log
2(4) is 2. Similarly, 2
3 = 8, so log
2(8) = 3. It turns out that 2
1.58496 is very nearly 3, so log
2(3) is roughly 1.58496.
Some cases deserve special mention. log
2(2) = 1 because 2
1 is 2. log
2(1) = 0 because by mathematical convention 2
0 = 1 (this holds not just for 2, but for any base). Finally, note that log
2(0) is undefined, although some software will return -Infinity (which is the limit of log
2(
x) as
x approaches zero).
What is it used for?The logarithm is useful for a variety of purposes. One of the more common is when describing exponential growth or decay. For example, the time for a radioactive substance to decay to half its mass is called the
half life. Similarly we can describe accelerating growth in terms of the
doubling time. I previously applied this to
the number of blogs tracked by Technorati.
In computing, log
2 is often used. One reason is that the number of bits needed to represent an integer
n is given by rounding down log
2(
n) and then adding 1. For example log
2(100) is about 6.643856. Rounding this down and then adding 1, we see that we need 7 bits to represent 100. Similarly, in order to have 100 leaves, a binary tree needs log
2(100) levels. In the game where you have to guess a number between 1 and 100 based on whether it's higher or lower than your current guess, the average number of guesses required is log
2(100) if you use a halving strategy to bracket the answer.
Two much of nothingAlthough I can't provide additional help to people with logarrhythmias, I hope this note is of some assistance.