Bit oriented operation

ReturnMethodSummary
static intbitCount(int i)Count the bits
static inthighestOneBit(int i)Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit.
static intlowestOneBit(int i)Returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit.

public class Main {
  public static void main(String[] args) {

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

The output:


2
8
2
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.