R
Raga
Hi,
There is a code for converting String to byte array, as follows:
"
public byte[] toByteArray(String s)
{
char[] c = s.toCharArray();
int len = c.length;
byte[] b = new byte[len * 2];
for ( int i = 0 ; i < len ; i++ )
{
b[i * 2] = (byte)(c);
b[(i * 2) + 1] = (byte)(c >> 8);
}
return b;
}
"
But this isn't doing the conversion properly. For example, for the €
(euro) symbol, it converts to some other unreadable symbol. Also, same
is the case for square brackets. Any idea why this' so? What's wrong
with the above code?
Thanks.
There is a code for converting String to byte array, as follows:
"
public byte[] toByteArray(String s)
{
char[] c = s.toCharArray();
int len = c.length;
byte[] b = new byte[len * 2];
for ( int i = 0 ; i < len ; i++ )
{
b[i * 2] = (byte)(c);
b[(i * 2) + 1] = (byte)(c >> 8);
}
return b;
}
"
But this isn't doing the conversion properly. For example, for the €
(euro) symbol, it converts to some other unreadable symbol. Also, same
is the case for square brackets. Any idea why this' so? What's wrong
with the above code?
Thanks.