Log base 2 in PHP

Discussion in 'PHP' started by NoamBarz, Apr 15, 2008.

  1. #1
    I need to find the log base 2 of a number. Is there a built in PHP function that can help? I was only able to find log base E or log base 10.
    Thanks...
     
    NoamBarz, Apr 15, 2008 IP
  2. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I got it. Sorry.
    The answer I came up with is:

    function Log2($x){
    return (log10($x) / log10(2));
    }

    Can anyone think of a better solution?
     
    NoamBarz, Apr 15, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    jayshah, Apr 15, 2008 IP