在 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.