解析十六進位制字串以在 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

更新時間:2020 年 6 月 29 日

1 千 + 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告