Jef*_*ter 21
将其解析为基数为2的整数,然后转换为字节数组.事实上,既然你已经有了16位,就可以打破很少使用的了short.
short a = Short.parseShort(b, 2);
ByteBuffer bytes = ByteBuffer.allocate(2).putShort(a);
byte[] array = bytes.array();
Run Code Online (Sandbox Code Playgroud)
Shr*_*ari 17
另一个简单的方法是:
String b = "0110100001101001";
byte[] bval = new BigInteger(b, 2).toByteArray();
Run Code Online (Sandbox Code Playgroud)