java.lang.Integer numberOfTrailingZeros(int i)

Description :

This java tutorial shows how to use the numberOfTrailingZeros() method of Integer class under java.lang package. This method returns an int which corresponds to the number of zeroes on the right most part of the 2’s complement equivalent of int method argument.

Method Syntax :

public static int numberOfTrailingZeros(int i)

Parameter Input :

DataType Parameter Description
int i the int value that we want to get the trailing zeroes or in other words the lowest order bit on its two's complement.

Method Returns :

The numberOfTrailingZeros(int i) method simply 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, or 32 if the value is equal to zero.

Compatibility Version :

Requires Java 1.5 and up

Exception :


Java Code Example :

This java example source code demonstrates the use of numberOfTrailingZeros() method of Integer class. Basically we only presented on how to use this method.


import static java.lang.System.*;

 * This example source code demonstrates 
 * the use of numberOfTrailingZeros method of Integer class

public class IntegerNumberOfLeadingZeros {

	public static void main(String[] args) {
		int value = 178;
		// Get the binary equivalent
		out.println("Binary equivalent:"+Integer.toBinaryString(value));
		// get the number of trailing zeros
		out.println("Number of Trailing Zeros:"+Integer.numberOfTrailingZeros(value));



Sample Output :

Running the numberOfTrailingZeros() method example source code of Integer class will give you the following output

Binary equivalent:10110010
Number of Trailing Zeros:1

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :