bitCount(): This method is available in java.math.BigInteger class of Java.
Syntax:
int java.math.BigInteger.bitCount()
It returns the number of bits in the two's complement representation of this BigInteger that differs from its sign bit. This method is useful when implementing bit-vector style sets atop BigIntegers.
Returns: number of bits in the two's complement representation of this BigInteger that differ from its sign bit.
For Example:
BigInteger bigInteger = new BigInteger("-12345")
bigInteger.bitCount() = > It returns 5.
Approach
Java
import java.math.BigInteger;public class BigIntegerbitCount {public static void main(String[] args) {BigInteger bigInteger = new BigInteger("-12345");System.out.println(bigInteger.bitCount());}}
Output:
5
No comments:
Post a Comment