Monday, October 12, 2020

Integer.bitCount() Method in Java

 


In this programming, I'm using "Integer.bitCount()" method. This method is in java.lang Package. This method returns only Integer value. "Integer.bitCount()" returns the number of one-bits in the two's complement binary representation of the specified int value.

Syntax :

public staic int bitCount(int n)  

Example :

public class Solution {  
    public static void main(String args[])  
    {  
        int n = 97 ;  
        System.out.println("Entered Integer number is: " + n );  
        // Conversion of integer number to binary  format  
        System.out.println("Binary Conversion: " +Integer.toBinaryString(n));  
        // print number of 1's in the number n  
        System.out.println("Number of 1's bit are: " +Integer.bitCount(n));  
    }  
}  

Output :

Entered Integer number is: 97
Binary Conversion: 1100001
Number of 1's bit are: 3
Follow us:


Location: Patna, Bihar, India

0 comments:

Post a Comment

Popular Posts

Recent Posts

Categories

Unordered List

Blog Archive

Contact Us

Name

Email *

Message *