Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write log base(2) in c/c++

Tags:

c++

c

Is there any way to write log(base 2) function?

The C language has 2 built in function -->>

1.log which is base e.

2.log10 base 10;

But I need log function of base 2.How to calculate this.

like image 572
russell Avatar asked Jun 17 '10 19:06

russell


People also ask

How do you type log2?

Open the document and place the cursor at the point where you want to insert the logarithm. Type "log," followed by the subscript icon given under the "Font" category of the "Home" tab. Type the base of the logarithm in subscript; for instance, "2." Press the subscript icon again to revert to normal font.

What is log2 base?

Log base 2 is the power to which the number 2 must be raised to obtain the value of n. For any real number x, log base 2 functions are written as. x = log2 n. Which is equal to. 2x = n.

How do you find the log base 2 of a log table?

Here it is always easier to find the value of log(2) to the base 10 and use it to find the value of the logarithm of 2 on any other basis. Using properties we can find the answer through calculations, close to the actual value. 10 *log(2) = log(1024). Since the base is also 10, we get log(2) = 3*0.1.


2 Answers

Simple math:

    log2 (x) = logy (x) / logy (2)

where y can be anything, which for standard log functions is either 10 or e.

like image 70
Adam Crume Avatar answered Sep 27 '22 21:09

Adam Crume


C99 has log2 (as well as log2f and log2l for float and long double).

like image 25
Matthew Flaschen Avatar answered Sep 27 '22 23:09

Matthew Flaschen