Bonjour,
J'aimerais convertir une chaine de caractère reçue de type :
en un tableau de bytesString str = "bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb bb "
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.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};
J'ai essayé le petit code suivant :Et j'obtiens alors le resultat 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]));
Donc pas du tout ma chaine initiale de nombres hexadécimaux.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
Si quelqu'un a une idée, je prends avec plaisir.
Merci d'avance
Partager