![]() |
VOOZH | about |
The bitCount() method of Integer class of java.lang package returns the count of set bits in a positive number. For negative numbers, it returns the count of set bits in its 2s complement form. This function is sometimes referred to as the population count.
Syntax:
public static int bitCount(int n)
Example 1: To show the working of java.lang.Integer.bitCount() method.
1010 2
Example 2:
Number of one-bits in num1: 2 Number of one-bits in num2: 30