在Java中为BigInteger设置一点
该setBit()方法在Java中用于返回一个BigInteger,其值等于具有指定位集的此BigInteger。
示例
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
BigInteger one, two;
one = new BigInteger("7");
two = one.setBit(3);
System.out.println("Result: " +two);
}
}输出结果
Result: 15
让我们来看另一个例子。
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger bi1, bi2;
bi1 = new BigInteger("9");
//使用索引3的setbit操作
bi2 = bi1.setBit(3);
String res = "Setbit operation on " +bi1+ " at index 3 gives " +bi2;
System.out.println(res);
}
}输出结果
Setbit operation on 9 at index 3 gives 9
热门推荐
6 简短平安夜祝福语
10 关于上岸成功祝福语简短
11 送生日祝福语简短高级
12 感恩朋友祝福语大全简短
13 生日祝福语简短给孩子
14 端午祝福语简短送老师
15 中考感言简短祝福语大全
16 周末新人祝福语大全简短
17 早安宝贝上学祝福语简短
18 酒桌上的简短祝福语