Java Data Type Tutorial - Java Long.bitCount(long i)








Syntax

Long.bitCount(long i) has the following syntax.

public static int bitCount(long i)

Example

In the following code shows how to use Long.bitCount(long i) method.

//from   ww  w.  jav  a 2  s  .co  m

public class Main {

   public static void main(String[] args) {

     long l = 100;
     System.out.println("Number = " + l);
    
     System.out.println("Binary = " + Long.toBinaryString(l));

     System.out.println("Number of one bits = " + Long.bitCount(l)); 
   }
}

The code above generates the following result.