Results 1 to 6 of 6
  1. #1
    RJNARESH is offline Member
    Join Date
    Jul 2008
    Posts
    1
    Rep Power
    0

    Default How to find logarithm base 2 value in java

    Please anyone tell me the way of how find a logarithmic value(base 2) for a number in java

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Sounds like a math question. Give us the algorithm for computing log(base 2) and we'll help you write the code.
    The Math class has several log methods.

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    also, there are trivial conversions for a log in one base to another. Smells like homework, so I'll let you do some real work on it.

  4. #4
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default fing log base 2

    log method of Math class gives us the natural logarithm of any given no. which is base e.
    You can convert it to any base , let's say n, using the equation,


    log x(base n)=log x(base e)/log n(base e)

  5. #5
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    Note that in the special case where you want the integer logarithm of an integer value, then you can get it from the highest set bit (or number of leading zeroes) of that number's binary representation, which is generally quicker to find.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. [SOLVED] base directory for servlets
    By Nicholas Jordan in forum Java Servlet
    Replies: 11
    Last Post: 07-04-2008, 11:29 PM
  2. Problems with Jtable connected to data base
    By elizabeth in forum AWT / Swing
    Replies: 2
    Last Post: 08-07-2007, 04:24 PM
  3. Replies: 1
    Last Post: 08-06-2007, 05:38 PM
  4. 2 threads sharing a data base connection
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 04:41 AM
  5. Connection to data base
    By Daniel in forum JDBC
    Replies: 2
    Last Post: 06-07-2007, 04:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •