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();
}
}

