设置 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");
// setbit operation using index 3
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP