mpjbuf
Class CustomMath

java.lang.Object
  extended by mpjbuf.CustomMath

public class CustomMath
extends java.lang.Object

A class that helps calculate natural log

Author:
Dirk Bosmans Dirk.Bosmans@tijd.com

Constructor Summary
CustomMath()
           
 
Method Summary
static int widthInBits(int n)
          Calculate how many bits wide a number is, i.e.
static int widthInBits1(int n)
          natural log method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomMath

public CustomMath()
Method Detail

widthInBits1

public static int widthInBits1(int n)
natural log method. Calculate how many bits wide a number is, i.e. position of highest 1 bit.

Returns:
p where 2**p is first power of two >= n. e.g. binary 0001_0101 -> 5, 0xffffffff -> 32, 0 -> 0, 1 -> 1, 2 -> 2, 3 -> 2, 4 -> 3

widthInBits

public static final int widthInBits(int n)
Calculate how many bits wide a number is, i.e. position of highest 1 bit. Fully unraveled binary search method.

Returns:
p where 2**p is first power of two >= n. e.g. binary 0001_0101 -> 5, 0xffffffff -> 32, 0 -> 0, 1 -> 1, 2 -> 2, 3 -> 2, 4 -> 3