解析和格式化 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