- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Integer.numberOfTrailingZeros() method in Java
The Integer.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 int value.
We have the following decimal as an example.
int dec = 199;
Calculated binary using Integer.toBinaryString() as shown below −
Integer.toBinaryString(dec);
Now let us see the implementation of Integer.numberOfTrailingZeros() method.
Example
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
Binary = 11000111 Count of one bits = 5 Number of trailing zeros : 0
Advertisements