English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java의 Integer.numberOfTrailingZeros() 메서드

The Integer.numberOfTrailingZeros() method returns the number of trailing zeros after the lowest order ("rightmost") zero bit in the binary representation of the specified int value.

Let's take the following decimal as an example.

int dec = 199;

Calculate binary using Integer.toBinaryString() as shown below-

Integer.toBinaryString(dec);

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

Example

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 result

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