public static void main(String[] args) {
//计算和
BigInteger num = new BigInteger("0");
num = num.setBit(1);
//2^1
//System.out.println(num);
//2^2+2^1
num = num.setBit(2);
//System.out.println(num);
//2^3+2^2+2^1
num = num.setBit(3);
//System.out.println(num);
//System.out.println(num.testBit(3));
int sum = (int) (Math.pow(2, 1)+Math.pow(2, 2)+Math.pow(2, 3));
System.out.println(sum);
// 00000010 00000100 00001000
// 2 4 8
// 00001110
System.out.println(sum & (int)(Math.pow(2, 3)));
//计算和
BigInteger num = new BigInteger("0");
num = num.setBit(1);
//2^1
//System.out.println(num);
//2^2+2^1
num = num.setBit(2);
//System.out.println(num);
//2^3+2^2+2^1
num = num.setBit(3);
//System.out.println(num);
//System.out.println(num.testBit(3));
int sum = (int) (Math.pow(2, 1)+Math.pow(2, 2)+Math.pow(2, 3));
System.out.println(sum);
// 00000010 00000100 00001000
// 2 4 8
// 00001110
System.out.println(sum & (int)(Math.pow(2, 3)));
}
如上代码可以通过其他方式得到,只为了知道内部原理是怎么操作的,本人记录使用。