Java Integer numberOfTrailingZeros() Method

The numberOfTrailingZeros() method is a method of Integer class under java.lang package. This method returns the total number of zero bits following the lowest-order ("rightmost") one's-bit in the two's complement binary representation of the specified integer value i.e. it converts int value to Binary then considers the right-most one bit and return total number of zero bits following it. In other words, if the specified integer value has no one-bits or is equal to zero in its two's complement representation then it will return 32.

Exaplanation:

Syntax:

Following is the declaration of numberOfTrailingZeros() method:

Parameter:

DataTypeParameterDescriptionRequired/Optional
intiIt accepts integer value which returns lowest order bit on its 2's complement.Required

Returns:

The 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 integer value, or 32 if the value is equal to zero.

Exceptions:

NA

Compatibility Version:

Java 1.5 and above

Example 1

Output:

Trailing Zero's: 1

Example 2

Output:

Binary equivalent: 111000
Number of Trailing Zeros: 3

Example 3

Output:

Enter the desired Integer value: 52
Binary equivalent: 110100
Number of Trailing Zeros: 2

Example 4

Output:

Input Number = -15
Number of Trailing Zeros = 0

Example 5

Output:

Trailing Zero's: 32