BigInteger bitCount() Method in Java Last Updated : 08 Nov, 2022 Comments Improve Suggest changes Like Article Like Report 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.Syntax: 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.Examples: Input: value = 2300 Output: 7 Explanation: Binary signed 2's complement of 2300 = 0000100011111100 Signed bit is 0 because 2300 is positive so no of 1 in 0000100011111100 is bitCount So bitCount in 0000100011111100 = 7 Input: value = 5482549 Output: 11 Below program illustrate the bitCount() method of BigInteger. Java /* *Program Demonstrate bitCount() method of BigInteger */ import java.math.*; public class GFG { public static void main(String[] args) { // Creates BigInteger objects BigInteger biginteger = new BigInteger("2300"); // Calling bitCount() method on bigInteger int count = biginteger.bitCount(); String result = "BitCount of " + biginteger + " is " + count; // Print result System.out.println(result); } } Output: BitCount of 2300 is 7 Reference : https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#bitCount() Comment More infoAdvertise with us Next Article BigInteger bitCount() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-lang package Java-Functions java-math Java-BigInteger Java-math-package +2 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger bitLength() Method in Java The java.math.BigInteger.bitLength() method returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit. For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. The bitLength method Computes (cei 1 min read BigInteger flipBit() Method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.flipBit(index) method returns a BigInteger which is used to flip a particular bit position in a BigInteger. This method Computes (bigInteger ^ (1<<n)). The bit at index n of binary representation of the bigInteger will be flipped. That i 2 min read BigInteger clearBit() Method in Java Prerequisite: BigInteger BasicsThe clearBit() method returns a BigInteger which is used to clear a particular bit position in a BigInteger. The bit at index n of binary representation of BigInteger will be cleared means converted to zero. Mathematically we can say that it is used to calculate this 2 min read BigInteger intValue() Method in Java The java.math.BigInteger.intValue() converts this BigInteger to an integer value. If the value returned by this function is too big to fit into integer value, then it will return only the low-order 32 bits. Further there is chance that this conversion can lose information about the overall magnitude 2 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read Like