Java Integer numberOfTrailingZeros() method
The numberOfTrailingZeros() method of Java Integer class returns the total number of zero bits following the lowest-order one-bit in the 2’s complement binary representation of the specified int value. Syntax public static int numberOfTrailingZeros (int i) Parameters The parameter ‘i’ represents a value whose number of trailing zeros is to be determined. Return Value This method returns:
- The Number of zero bits following the lowest-order one-bit in the 2’s complement binary representation.
- 32 if the value is equal to zero.
public class JavaIntegerNumberOfTrailingZerosExample2 { public static void main(String[] args) { Integer val1=76; //returns the Number of zero bits following the lowest-order one-bit in the 2’s complement binary representation int i= Integer.numberOfTrailingZeros(val1); System.out.println("Number of trailing zeros returned : "+i); } }Output
Number of trailing zeros returned : 2Example 2
public class JavaIntegerNumberOfTrailingZerosExample2 { public static void main(String[] args) { Integer val1=0; //returns 32 if the value is equal to zero int i= Integer.numberOfTrailingZeros(val1); System.out.println("Number of trailing zeros returned : "+i); } }Output
Number of trailing zeros returned : 32Example 3
public class JavaIntegerNumberOfTrailingZerosExample3 { public static void main(String[] args) { Integer val1=Integer.MIN_VALUE; int i= Integer.numberOfTrailingZeros(val1); System.out.println("Number of trailing zeros returned : "+i); } }Output
Number of trailing zeros returned : 31