Get the number of zero bits preceding and following

ReturnMethodSummary
static intnumberOfLeadingZeros(long i)Returns the number of zero bits preceding the highest-order one-bit in binary.
static intnumberOfTrailingZeros(long i)Returns the number of zero bits following the lowest-order one-bit in binary.

public class Main {
  public static void main(String[] args) {
    System.out.println(Long.numberOfLeadingZeros(123123));
  }
}

The output:


47
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.