Java BigInteger bitCount() Method

The bitCount() method of Java BigInteger class is used to count the number of set bits. This method returns the number of bits in the two's complement representation of this BigInteger that differ from the sign bit of this BigInteger.

Syntax:

Returns:

This method returns number of bits that differ from this BigInteger's sign bit.

Note:
  • This method returns number of set bits if this BigInteger value is positive.
  • This method returns number of reset bits if this BigInteger value is negative.

Example

Test it Now

Output:

Result of bitCount operation on 7 is 3
Result ofbitCount operation on -7 is 2

Next TopicJava BigInteger




Latest Courses