Prerequisite: BigInteger Basics
The java.math.BigInteger.bitCount() method returns number of bits in the two’s complement representation of this BigInteger that differ from its sign bit. This method is useful when implementing bit-vector style sets atop BigIntegers.
public int bitCount()
Parameters: The method does not take any parameters.
Return Value: The method is used to return the number of bits in the two’s complement representation of this BigInteger that differ from its sign bit.
Input: value = 2300 Output: 8 Explanation: Binary signed 2's complement of 2300 = 0000100011111100 Singned bit is 0 because 2300 is positive so no of 1 in 0000100011111100 is bitCount So bitCount in 0000100011111100 = 8 Input: value = 5482549 Output: 11
Below program illustrate the bitCount() method of BigInteger.
BitCount of 2300 is 7
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.