Javatpoint Logo
Javatpoint Logo

Java Integer bitCount() method

The bitCount() is a method of Integer class under java.lang package. It returns the number of one-bits in the two's complement binary representation of the specified int value. This function is sometimes referred to as the population count.

Syntax

Following is the declaration of bitCount() method:

Parameter:

DataType Parameter Description Required/Optional
int i It is an integer value enter by user Required

Returns:

The bitCount() method returns the number of one-bits in the two's complement binary representation of the specified int value.

Exceptions:

NA

Compatibility Version:

Java 1.5 and above

Example 1

Test it Now

Output:

100011
3

Example 2

Test it Now

Output:

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

Example 3

Output:

Enter the Integer value: 23
The input number is: 23
Binary Conversion: 10111
Number of 1's bit are: 4

Next TopicbyteValue() Method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA