[英]Convert a string of bits to unicode character in java
I'm trying to convert a string of bits into Unicode characters in java. 我正在尝试将一串位转换为Java中的Unicode字符。 Problem is that I only get chines signs etc.
问题是我只会得到中国标志等。
String bits = "01010011011011100110000101110010" 字符串位=“ 01010011011011100110000101110010”
Anyone know how to do this? 有人知道怎么做吗?
Use Integer.parseInt
to parse the binary string, then convert it to byte array (using ByteBuffer
) and finally convert byte array to String
: 使用
Integer.parseInt
解析二进制字符串,然后将其转换为字节数组(使用ByteBuffer
),最后将字节数组转换为String
:
String bits = "01010011011011100110000101110010"
new String(
ByteBuffer.allocate(4).putInt(
Integer.parseInt(bits, 2)
).array(),
StandardCharsets.UTF_8
);
For arbitrary large bits
String you can use also BigInteger
: 对于任意的大
bits
的字符串,你也可以使用BigInteger
:
new String(
new BigInteger(bits, 2).toByteArray(),
StandardCharsets.UTF_8
);
Snar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.