Bonjour,
J'aimerais convertir une chaine de caractère reçue de type :
String str = "bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb "
en un tableau de bytes
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 : Sélectionner tout - Visualiser dans une fenêtre à part
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 :
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