Calculating Log base 2

As can be seen in MSDN http://msdn.microsoft.com/en-us/library/x80ywz41.aspx

The Math.Log function computes the log with base e.

See http://msdn.microsoft.com/en-us/library/hd50b6h5.aspx for what you need.


Math.Log(num) returns the log of base e

Math.Log(num, base) is probably what you are looking for.


When calling the Log method with only a single argument, you get the Log base e. If you provide the second argument of 2.0, you get the result you expect:

//Testing in LinqPad
void Main()
{
    Math.Log(3.83031869).Dump();
    Math.Log(3.83031869, 2.0).Dump();
}

Results

1.34294800860817
1.93746443219072

Tags:

C#

C# 4.0