Conversion d'une chaine de caractères en un tableau de bytes
Bonjour,
J'aimerais convertir une chaine de caractère reçue de type :
Citation:
String str = "bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb "
en un tableau de bytes
Citation:
byte[] byte_array = {(byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB,
(byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB, (byte) 0xBB};
car j'ai besoin dans la suite de mon code de manipuler ce tableau de bytes et donc d'être sure qu'il contient les bonnes valeurs.
J'ai essayé le petit code suivant :
Code:
1 2 3 4 5 6 7 8 9
|
String str = "bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb ";
byte [] byte_array = new byte [16];
byte_array = str.getBytes();
System.out.println(str);
System.out.println(byte_array.toString());
for(int i = 0x00; i <= 0x0F; i++)
System.out.print(String.format("%x ", byte_array[i])); |
Et j'obtiens alors le resultat suivant :
Citation:
bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb
[B@addbf1
62 62 20 62 62 20 62 62 20 62 62 20 62 62 20 62
Donc pas du tout ma chaine initiale de nombres hexadécimaux.
Si quelqu'un a une idée, je prends avec plaisir.
Merci d'avance