Integer.numberOfTrailingZeros() method in Java


The Integer.numberOfTrailingZeros() method returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified int value.

We have the following decimal as an example.

int dec = 199;

Calculated binary using Integer.toBinaryString() as shown below −

Integer.toBinaryString(dec);

Now let us see the implementation of Integer.numberOfTrailingZeros() method.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      int dec = 199;
      System.out.println("Binary = " + Integer.toBinaryString(dec));
      System.out.println("Count of one bits = " + Integer.bitCount(dec));
      System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(dec));
   }
}

Output

Binary = 11000111
Count of one bits = 5
Number of trailing zeros : 0

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

75 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements