English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How to know if a number is a power of 2? It must have a mathematical formula somewhere...

2007-05-04 14:04:51 · 3 answers · asked by margagn 1 in Science & Mathematics Mathematics

3 answers

If you receive an integer value when taking a logarithm of base 2 of the number, then it is a power of 2. For instance, if you're checking to see if the number 1024 is a power of 2, you can type this into your calculator:

log(1024) / log(2)

The log button on the calculator refers to a logarithm of base 10, but the formula above is the equivalent of taking a logarithm of base 2. Basically, you're checking to see if:

2^y = x

Where y is the exponent returned by log(1024) / log(2) and x is the integer in question. A logarithm will allow you to isolate the variable exponent and determine its value.

Again, if you get an integer result, then it is a power of 2. In this case you will get 10, and thus 1024 is a power of 2. The general formula for checking this kind of problem, is:

log(x) / log(b)

Where x is the integer in question and b is the base of the exponent (ie. checking what value x is a power of). Hope that helps =)

2007-05-04 14:12:11 · answer #1 · answered by Bhajun Singh 4 · 1 0

You could find the log base 2 of the number. If the answer's an integer, it's a power of 2. Or keep dividing it by 2 and if you never get an odd number until you get 1, then it's a power of 2.

2007-05-04 14:14:37 · answer #2 · answered by John 5 · 3 0

Let x be the natural log of 2. Then ln (2) = x.

Let y be the natural log of the number, N, you are testing. Then ln (N) = y.

Now take the ratio of their natural logs:

ln (N) / ln (2) = k. If k is an integral multiple of ln (2), then N is a power of 2.

Here's proof:

ln (2) = x ----> e^x = 2
ln (N) = y -----> e^y = N

ln (N) / ln (2) = y/x = k.

If y is an integral multiple of ln (2), then y = kx. That implies e^y = e^kx = e^xk = (e^x)^k = (2)^k. Then ln (N) / ln (2) becomes ln (2)^k / ln (2) = k ln (2) / ln (2) = k [ln (2) / ln (2)] = k (1) = k.

Thus, if N is a power of 2, its natural log is an integral multiple of the natural log of 2.

2007-05-04 14:10:43 · answer #3 · answered by MathBioMajor 7 · 1 2

fedest.com, questions and answers