在 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP