I think this is what you’d like to know:
b^x=y
x=log(y)/log(b)
For b=2 and y=11 you could write something like this:
x=log(11)/log(2),
where b is the logarithm base, whilst y is the logarithm argument.
Therefore, you can calculate any logarithm in a programming language by evaluating it to base 10 first, then dividing it by the logarithm of the base, also using the logarithm to base 10.
Here are some examples in various programming languages:
C#
using System;
namespace ConsoleApplicationTest
{
class Program
{
static void Main(string[] args)
{
double x = Math.Log10(11) / Math.Log10(2);
Console.WriteLine("The value of x is {0}.", x);
}
}
}
C++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = log10(11)/log10(2);
cout << "The value of x is " << x << "." << endl;
return 0;
}
JavaScript
var x = Math.log(11)/Math.log(2);
document.write("The value of x is "+x+".");
Tim has already shown a Python example.
solved about log(n),how to calculate? [closed]