Java Bit Get bits(int i)

Here you can find the source of bits(int i)

Description

Compute the integer logarithms (ceil(log(x+1)) of a value

License

Open Source License

Parameter

Parameter Description
i source value

Return

integer logarithm

Declaration

public static int bits(int i) 

Method Source Code

//package com.java2s;
/**/*ww w  .j a  v a 2s  .  c  o  m*/
 * This code is released under the
 * Apache License Version 2.0 http://www.apache.org/licenses/.
 *
 * (c) Daniel Lemire, http://lemire.me/en/
 */

public class Main {
    /**
     * Compute the integer logarithms (ceil(log(x+1)) of a value
     * 
     * @param i
     *            source value
     * @return integer logarithm
     */
    public static int bits(int i) {
        return 32 - Integer.numberOfLeadingZeros(i);
    }
}

Related

  1. bitAt(byte b, int pos)
  2. bitAt(int offset, byte aByte)
  3. bitAt(int offset, byte aByte)
  4. bits(int i)
  5. bits(int n, int offset, int length)
  6. bits(int value, int c)
  7. bits(int value, int first, int last)
  8. bits(long maxValue)