設定 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