解析和格式化 Java 中的位元組陣列為二進位制
設定 BigInteger 物件。
BigInteger one;
現在,建立一個 ByteArray。
byte byteArr[] = new byte[] { 0x1, 0x00, 0x00 };
one = new BigInteger(byteArr);對於Binary,我們使用 2 作為 toString() 方法引數。
String strResult = one.toString(2);
下面是一個示例 −
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
// BigInteger object
BigInteger one;
byte byteArr[] = new byte[] { 0x1, 0x00, 0x00 };
one = new BigInteger(byteArr);
String strResult = one.toString(2);
System.out.println("ByteArray to Binary = "+strResult);
}
}輸出
ByteArray to Binary = 10000000000000000
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP