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


設定 BigInteger 物件。

BigInteger one;

現在,建立一個 ByteArray。

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

對於八進位制,我們使用 8 作為 toString() 方法引數。

String strResult = one.toString(8);

以下是一個示例 -

示例

 即時演示

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);
      // Octal
      String strResult = one.toString(8);
      System.out.println("ByteArray to Octal = "+strResult);
   }
}

輸出

ByteArray to Octal = 200000

更新於: 2020-06-29

539 次瀏覽

開啟你的 事業

完成學習,獲得證書

開始
廣告
© . All rights reserved.