在 Java 中從位元組陣列建立 BigInteger


BigInteger 類提供了用於算術模運算、最大公約數計算、質數測試、質數生成、位操作和其他一些雜項運算的操作。

假設以下內容是我們的位元組陣列 -

byte[] arr = new byte[] { 0x1, 0x00, 0x00 };

我們現在將它們轉換為 BigInteger -

BigInteger bInteger = new BigInteger(arr);

以下是一個示例,其中在 Java 中從位元組陣列建立 BigInteger。

示例

 線上演示

import java.math.BigInteger;
public class Demo {
   public static void main(String[] argv) throws Exception {
      byte[] arr = new byte[] { 0x1, 0x00, 0x00 };
      BigInteger bInteger = new BigInteger(arr);
      System.out.println(bInteger);
   }
}

輸出

65536

更新於: 06-29-2020

2K+ 瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.