I think what you really want to do is convert a binary (decimal) number to its ASCII representation. If so, try something like this:
public class ByteArrayToAsciiChar {
public String byteToCharacter(byte b) {
return Character.valueOf((char)b).toString();
}
public static void main(String[] args) {
byte[] byteArray = {
0b00100101,
0b01000001,
0b01100001,
0b01000010,
0b01100010,
0b01010101
};
ByteArrayToAsciiChar testClass = new ByteArrayToAsciiChar();
for (byte b : byteArray) {
System.out.println("Byte: " + b + " ==> " + testClass.byteToCharacter(b));
}
}
}
Which gives this output:
Byte: 37 ==> %
Byte: 65 ==> A
Byte: 97 ==> a
Byte: 66 ==> B
Byte: 98 ==> b
Byte: 85 ==> U
HTH