Java Integer.numberOfTrailingZeros(int i) example

# Java Integer.numberOfTrailingZeros(int i) example

By Yashwant Chavan, Views 3, Date 21-Apr-2018

In this java tutorial, You will learn how to use numberOfTrailingZeros(int i) method of class Integer. This method 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. Returns 32 if the specified value has no one-bits in its two's complement representation, in other words if it is equal to zero.

tags Java

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.

## Syntax

```public static int numberOfTrailingZeros(int i)
```

## 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.

## Java Integer numberOfTrailingZeros(int i) example

• Assign two integer values.
• `Integer.numberOfTrailingZeros(firstValue);`It will return the number of leading zeros in firstValue.
• `Integer.numberOfTrailingZeros(secondValue);`It will return the number of leading zeros in secondValue.
• Print the values.
```package com.technicalkeeda;

public class App {

public static void main(String[] args) {

Integer firstValue = 125;
Integer secondValue = 42;

int result1 = Integer.numberOfTrailingZeros(firstValue);
int result2 = Integer.numberOfTrailingZeros(secondValue);

System.out.println("Number of trailing zeros in firstValue :- " + result1);
System.out.println("Number of trailing zeros in secondValue :- " + result2);
}
}
```

## output

```Number of trailing zeros in firstValue :- 0
Number of trailing zeros in secondValue :- 1
```

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]