在 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