Wednesday, September 28, 2005

Codigo de Java para convertir Hex To Str

/**
* Converts a string to the char representations of its hex.
*/
Selection[] selection = textArea.getSelection();
String s = textArea.getSelectedText(selection[0]);
StringBuffer sb = new StringBuffer();

byte b;
String unidos = "";

for (int x = 0; x < s.length(); x++) {
unidos = "";
unidos += s.charAt(x);
unidos += s.charAt(++x);
b = Byte.valueOf(unidos, 16).byteValue();
sb.append((char)Integer.parseInt(Byte.toString(b)));
}
textArea.setSelectedText(selection[0],sb.toString());

No comments: