Currently, I have a String with the value "0100100001101001" (this is binary for the word 'Hi'). I'm trying to figure out how to take that string and convert it back into the word "Hi"
I used
String s = "Hi";
byte[] bytes = s.getBytes();
StringBuilder binary = new StringBuilder();
for (byte b : bytes)
{
int val = b;
for (int i = 0; i < 8; i++)
{
binary.append((val & 128) == 0 ? 0 : 1);
val <<= 1;
}
}
s = binary.toString();
found on: Convert A String (like testing123) To Binary In Java
Any help would be much appreciated. Thanks in advance.