关于bigInteger中setbit 和 testBit的解析
来源:互联网 发布:淘宝培训班zz px 编辑:程序博客网 时间:2024/06/06 00:50
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);
// 0000001000000100 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);
// 0000001000000100 00001000
// 2 4 8
// 00001110
System.out.println(sum & (int)(Math.pow(2, 3)));
}
如上代码可以通过其他方式得到,只为了知道内部原理是怎么操作的,本人记录使用。
0 0
- 关于bigInteger中setbit 和 testBit的解析
- 使用BigInteger.setBit与BigInteger.testBit来实现权限控制
- 使用BigInteger.setBit与BigInteger.testBit来实现权限控制
- BigInteger.testBit(int n)与setBit(int n)
- setBit testBit权限管理
- Redis中setbit和bitcount的注意细节
- 关于java中BigInteger的用法
- redis中 SETBIT命令 和 BITCOUNT命令
- redis 中 SETBIT命令的用法
- BigInteger权限判断示例,权限计算,setBit
- java权限控制BigInteger.setBit()详解
- Java.math.BigInteger.testBit()方法实例 权限设置
- JAVA中大数字的的处理:BigInteger和BigDecimal
- java.math中NumberFormat,BigInteger和BigDecimal的简单用法
- redis的setbit和getbit是干嘛的???
- Oracle 中设置位的值函数SETBIT(原创)
- java中BigInteger的用法
- Java中BigInteger的使用
- Map-HashMap与TreeMap
- 日志-nginx的access_log与error_log
- fio-基本测试命令
- 新环境中奋起的岁月(六)
- list转json的时候,关于date转换的问题
- 关于bigInteger中setbit 和 testBit的解析
- 天线经验
- Ruby & Rails install for mac
- 最小生成树——普里姆(Prim)算法
- 剑指:根据输入的前序和中续遍历序列重建二叉树
- LoadRunner快速使用入门之Vugen
- 数据结构与基本算法的学习笔记-顺序搜索-2
- github命令行挑战
- CAMERA预览数据流程分析(一)-------数据的获取