How do I convert the binary representation of a string back to a string?

I have a string that has been converted to binary with Integer.toBinaryString () for each of its characters. Then the binary string was a bit garbled (random bits are flipped) and I would like to convert it back to a string. Are there any simple methods to do this in java?

0


source to share


1 answer


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

.



In your case, radix 2

, so you just need to split the whole binary string into 8 character substrings and use Integer.parseInt(substring, 2)

. Then you convert them to symbols and concatenate them.

+1


source







All Articles