Conversion Issue

I am using some extended ASCII characters. To convert it from byte to hex and the back from hex to byte and to it original string. The problem is only with extended ASCII characters. Where it puts the question marks.

Please guide me with the code displayed below

Thanking you in advance.

publicclass Hex_Byte{

privatestaticfinalchar[] hex ="0123456789ABCDEF".toCharArray();

publicstaticvoid main(String args[]){

String textSample ="ABCDFE1234567890z嫫";

System.out.println("OrignalString: " + textSample);

byte[] strToByte = textSample.getBytes();

String hex = asHex(strToByte);

byte[] bts =new BigInteger(hex, 16).toByteArray();

String revertString ="";

for (int i = 0; i < bts.length; i++)

revertString += ((char)bts[i] +"");

System.out.println("RevertString: " + revertString);

}

publicstatic String asHex (byte buf[]){

StringBuffer strbuf =new StringBuffer(buf.length * 2);

int i;

for (i = 0; i < buf.length; i++){

if (((int) buf[i] & 0xff) < 0x10)

strbuf.append("0");

strbuf.append(Long.toString((int) buf[i] & 0xff, 16));

}

return strbuf.toString();

}

}

[2462 byte] By [muhammadowaisa] at [2007-11-27 5:52:39]
# 1
use .getBytes("<encoding>"); to make sure you use an encoding that supports those extended characters.
-Kayaman-a at 2007-7-12 15:44:04 > top of Java-index,Java Essentials,Java Programming...
# 2
The default encoding is ISO-8859-1 and these characters fall in this encoding
muhammadowaisa at 2007-7-12 15:44:04 > top of Java-index,Java Essentials,Java Programming...
# 3
Use the String(byte[]) constructor to convert an array of bytes to a string.
jsalonena at 2007-7-12 15:44:04 > top of Java-index,Java Essentials,Java Programming...
# 4
new String(myByte) worked. thanks
muhammadowaisa at 2007-7-12 15:44:04 > top of Java-index,Java Essentials,Java Programming...