English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
We take the following decimal as an example.
int dec = 199;
Calculate the binary using Integer.toBinaryString() as shown below-
Integer.toBinaryString(dec);
Let's take a look at the implementation of the Integer.numberOfTrailingZeros() method now.
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