How to calculate log2 without the real function

log2In computer science, being able to count in binary is pretty much a prerequisite. So too is being able to quickly work out the decimal range of a binary number by just knowing its length in bits. For example, an 8-bit number has 256 levels; a 10-bit number 1024; a 16-bit number 65536.

But working back the other way – this is, finding the number of bits based on the number of levels – is a bit harder. Calculators have a ‘log10’ function, but not log2.

It’s actually a pretty useful function to know. For example, if you’re trying to work out the channel capacity of a signal, the formula follows the Nyquist Theorem:

Data rate = 2 x f x log2 (L)

Where f is the signal frequency and L is the number of levels the signal supports.

The simplest way to do a log2 function on a calculator with a log10 function only is as follows:

log2 (x) = log10 (x) / log10 (2)

So, for example, let’s say we want to know what log2 (65536) is. We know the answer is 16 because 2 to the power of 16 is 65536.

But using our log function, we get:

log2 (65536) = log10 (65536) / log10 (2) =  4.8164799 / 0.30102999

= 16

But really, you can use this trick to work out the log of any radix by simply dividing the log10 of the number by the log10 of the radix.

For example:

log3 (27) = log10 (27) / log10 (3) = 3

Remember it for your next exam! :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *