Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中将一串位转换为unicode字符_Java_Unicode_Byte_Bits - Fatal编程技术网

在java中将一串位转换为unicode字符

在java中将一串位转换为unicode字符,java,unicode,byte,bits,Java,Unicode,Byte,Bits,我试图在java中将一串位转换成Unicode字符。问题是我只看到中国的标志等等 字符串位=0101001101110011000010110010 有人知道怎么做吗?值为32位 对于任意大位字符串,也可以使用BigInteger: 后果 您的代码是什么?0101001101110011000010110010应该转换成什么?如果位字符串长于64位怎么办?这不适用于LongWell,OP只给我们展示了一个例子,它适用于integerOP展示的例子,但没有明确指出位字符串不能超过64,我认为我们不

我试图在java中将一串位转换成Unicode字符。问题是我只看到中国的标志等等

字符串位=0101001101110011000010110010

有人知道怎么做吗?

值为32位 对于任意大位字符串,也可以使用BigInteger:

后果
您的代码是什么?0101001101110011000010110010应该转换成什么?如果位字符串长于64位怎么办?这不适用于LongWell,OP只给我们展示了一个例子,它适用于integerOP展示的例子,但没有明确指出位字符串不能超过64,我认为我们不能假设:@niceman是的,很好。我添加了一个更简单的例子来说明这一点:如果第一位为1,也就是说,如果第一个字符的代码点为U+0100或更高,那么这可能会出现错误,因为字节数组必须有一个额外的填充字节,以确保符号位为0。
String bits = "01010011011011100110000101110010"
new String(
    ByteBuffer.allocate(4).putInt(
        Integer.parseInt(bits, 2)
    ).array(), 
    StandardCharsets.UTF_8
);
new String(
    new BigInteger(bits, 2).toByteArray(),
    StandardCharsets.UTF_8
);
Snar