开发者

How to convert a binary representation of a string back into a string?

开发者 https://www.devze.com 2022-12-26 13:08 出处:网络
I have a string that was converted to binary with Integer.toBinaryString() on each of its characters.The binary string was then mangled a bit (random bit flips) and I\'d like to conver开发者_Go百科t i

I have a string that was converted to binary with Integer.toBinaryString() on each of its characters. The binary string was then mangled a bit (random bit flips) and I'd like to conver开发者_Go百科t it back into a string. Are there any simple methods for this in java?


Yes, you can easily do it using Integer.parseInt(String s, int radix).

In your case the radix is 2 so you just have to split your whole binary string in substrings of 8 chars each and use Integer.parseInt(substring, 2). Then you convert them to characters and you concatenate them..

0

精彩评论

暂无评论...
验证码 换一张
取 消