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