View Full Version : [JAVA] Convertire stringa in array di esadecimali
Ciao a tutti,
sto sviluppando un programmino in Java....
Come si fa a convertire stringa in array di esadecimali???
Ad esempio:
String x="prova";
vorrei ottenere 70 72 6f 76 61;
banryu79
30-10-2009, 17:19
Una possibile soluzione potrebbe essere questa:
// data la String s, stampa il valore esadecimale di ogni carattere di cui e' composta
private void printHex(String s) {
char[] chars = s.toCharArray();
for (char c : chars) {
String hex = Integer.toHexString((int)c);
System.out.println(hex);
}
}
Una possibile soluzione potrebbe essere questa:
// data la String s, stampa il valore esadecimale di ogni carattere di cui e' composta
private void printHex(String s) {
char[] chars = s.toCharArray();
for (char c : chars) {
String hex = Integer.toHexString((int)c);
System.out.println(hex);
}
}
Grazie fa al caso mio!!
Perņ ora ottengo cmq una stringa hex.
Come faccio ad assegnarla ad una variabile di tipo Byte?
ad esempio:
Byte x=(byte)hex;
Ma nn funziona...
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.