Java Bit Count countBitsNeeded(int value)

Here you can find the source of countBitsNeeded(int value)

Description

Find out number of bits needed to represent a positive integer

License

Open Source License

Parameter

Parameter Description
value unsigned 32 bit int value

Return

number of bits needed to store a value

Declaration

public final static int countBitsNeeded(int value) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from ww w  . j  ava2  s .  co m
     * Find out number of bits needed to represent a positive integer
     *
    * @param value unsigned 32 bit int value
    * @return number of bits needed to store a value
     */
    public final static int countBitsNeeded(int value) {
        return Integer.SIZE - Integer.numberOfLeadingZeros(value);
    }
}

Related

  1. countBits(int x)
  2. countBits(int x)
  3. countBits(long num)
  4. countBits(long value)
  5. countBitsInMask(int mask)
  6. countBitsSet(int bitfield)