I don't find a way to convert byte[] array into ASCII format, i.e. String.
String message=New String (abytearray);
is it suitable??
Printable View
I don't find a way to convert byte[] array into ASCII format, i.e. String.
String message=New String (abytearray);
is it suitable??
String message = "";
byte[] abytearrray = { 1, 4, 6, 9, 1 };
for(byte element:abytearray) {
message += Byte.toString(element);
}
That should work.
-MK12
yes new String(byteArray) is quite suitable.
Oh that works?
Ok that would go faster then. Do what Fubarable said.
-MK12
for instance:
Code:public static void main(String[] args)
{
byte[] hexArray =
{
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65,
0x73, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x65, 0x65, 0x20, 0x69, 0x66,
0x20, 0x6e, 0x65, 0x77, 0x20, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28,
0x62, 0x79, 0x74, 0x65, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x29, 0x20,
0x77, 0x6f, 0x72, 0x6b, 0x73, 0x2e
};
System.out.println(new String(hexArray));
}
Your test code is really creative. Thank you ;)
Sorry for typo Fubarable. Can I ask you why you use 0x before Ascii codes?
0x is not used for ASCII codes, it's to tell Java that the number is in hexadecimal format.