解析十六進位制字串以在 Java 中建立 BigInteger
要解析十六進位制字串以建立 BigInteger,可使用以下 BigInteger 建構函式,並將十六進位制的基數設定為 16。
BigInteger(String val, int radix)
使用此建構函式可將指定基數的 BigInteger 字串表示形式轉換為 BigInteger。
在以下示例中,我們設定了 BigInteger,基數設定為 16 −
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two;
String hexStr = "290f98";
one = new BigInteger("250");
// parsing
two = new BigInteger(hexStr, 16);
System.out.println("Result (BigInteger) : " +one);
System.out.println("Result (Parsing Hex String) : " +two);
}
}輸出
Result (BigInteger) : 250 Result (Parsing Hex String) : 2690968
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP