Example usage for java.lang Integer highestOneBit

List of usage examples for java.lang Integer highestOneBit

Introduction

In this page you can find the example usage for java.lang Integer highestOneBit.

Prototype

public static int highestOneBit(int i) 

Source Link

Document

Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int value.

Usage

From source file:Main.java

public static void main(String[] args) {

    System.out.println(Integer.highestOneBit(10));
}

From source file:MainClass.java

public static void main(String args[]) {
    int n = 170;/*from   ww w  . j a  v  a  2  s .  co  m*/

    System.out.println("Highest one bit: " + Integer.highestOneBit(n));
}

From source file:Bits.java

public static void main(String args[]) {
    int n = 170; // 10101010 
    System.out.println("Value in binary: 10101010");

    System.out.println("Number of one bits: " + Integer.bitCount(n));

    System.out.println("Highest one bit: " + Integer.highestOneBit(n));

    System.out.println("Lowest one bit: " + Integer.lowestOneBit(n));

    System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n));

    System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n));

    System.out.println("\nBeginning with the value 1, " + "rotate left 16 times.");
    n = 1;/*from   ww  w .  j a  v a 2s .  com*/
    for (int i = 0; i < 16; i++) {
        n = Integer.rotateLeft(n, 1);
        System.out.println(n);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    int n = 170; // 10101010

    System.out.println("Value in binary: 10101010");

    System.out.println("Number of one bits: " + Integer.bitCount(n));

    System.out.println("Highest one bit: " + Integer.highestOneBit(n));

    System.out.println("Lowest one bit: " + Integer.lowestOneBit(n));

    System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n));

    System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n));

    System.out.println("\nBeginning with the value 1, " + "rotate left 16 times.");
    n = 1;//from  w w  w .ja v  a 2  s .  c o m
    for (int i = 0; i < 16; i++) {
        n = Integer.rotateLeft(n, 1);
        System.out.println(n);
    }

}

From source file:Main.java

public static int getPowerOfTwoForSampleRatio(double ratio) {
    int k = Integer.highestOneBit((int) Math.floor(ratio));
    if (k == 0)/*w w  w.  j a v a 2s  .c o  m*/
        return 1;
    else
        return k;
}

From source file:Main.java

private static int getPowerOfTwoForSampleRatio(double ratio) {
    int k = Integer.highestOneBit((int) Math.floor(ratio));
    if (k == 0)//from  w w  w . j a  v  a  2 s. co  m
        return 1;
    else
        return k;
}

From source file:Main.java

public static int prevPowerOf2(int n) {
    if (n <= 0)
        throw new IllegalArgumentException();
    return Integer.highestOneBit(n);
}

From source file:Main.java

private static int prevPowerOf2(int n) {
    if (n <= 0) {
        throw new IllegalArgumentException();
    }/*from  w ww.ja  va 2 s.  c  o m*/
    return Integer.highestOneBit(n);
}

From source file:Main.java

public static int getNextHigherPowerOfTwo(int num) {
    if (num <= 0)
        return 1;
    int highestBit = Integer.highestOneBit(num);
    return num <= highestBit ? highestBit : highestBit << 1;
}

From source file:Main.java

public static int prevPowerOf2(final int n) {
    if (n <= 0) {
        throw new IllegalArgumentException();
    }/* w  ww.  jav a2s .c  o m*/
    return Integer.highestOneBit(n);
}