在 Java 中解析位元組陣列並將其格式化為十進位制


設定一個 BigInteger 物件。

BigInteger one;

現在,建立一個 ByteArray −

byte byteArr[] = new byte[] { 0x1, 0x00, 0x00 };
one = new BigInteger(byteArr);

對於 Decimal,我們使用的是 toString() 方法,沒有引數值。

String strResult = one.toString();

以下是一個示例 −

示例

 即時演示

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger one;
      // ByteArray
      byte byteArr[] = new byte[] { 0x1, 0x00, 0x00 };
      one = new BigInteger(byteArr);
      // Decimal
      String strResult = one.toString();
      System.out.println("ByteArray to Decimal = "+strResult);
   }
}

輸出

ByteArray to Decimal = 65536

更新於: 2019 年 7 月 30 日

2K+ 檢視數

啟動你的 職業生涯

完成課程獲得認證

開始
廣告