Online Java Compiler By
JavaTpoint.com
import java.math.BigInteger; public class BigIntegerBitCountExample { public static void main(String[] args){ // create 2 BigInteger objects BigInteger big1,big2 ; // create 2 int objects int i1,i2 ; // assign values to big1, big2 big1= new BigInteger("7"); // 0111 big2 =new BigInteger("-7"); // 1001 //perform bitCount operation on big1, big2 i1 = big1.bitCount(); //total no of set bits or 1's i2 = big2.bitCount(); //total no of set bits or 1's String str1="Result of bitCount operation on "+ big1+" is "+ i1; String str2="Result of bitCount operation on "+ big2+" is"+ i2; System.out.println(str1); System.out.println(str2); } }
Output