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 convert it back into a string. Are there any simple methods for this in java?
+1
A:
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..
Jack
2010-04-09 15:59:47
Interesting. I've never seen this used before. Similarly, would converting from hex be done with radix 16? Or have I interpreted the use incorrectly?
Terri
2010-04-09 16:03:45
Yes, that's it..
Jack
2010-04-09 16:21:33