Le code ressemble à ceci:
/ * Entrez un octet et octet [] fusionnez en octet [] * / byte public [] bytememerger (byte byte_1, byte [] byte_2) {byte [] byte_3 = new byte [1 + byte_2.length]; byte_3 [0] = byte_1; System.ArrayCopy (byte_2, 0, byte_3, 1, byte_2.length); retour byte_3; } / * Entrez un octet [] et octet [] fusionner dans Byte [] * / public byte [] byteMerger (byte [] byte_1, byte [] byte_2) {byte [] byte_3 = new byte [1 + byte_2.length]; byte_3 [0] = byte_1; System.ArrayCopy (byte_2, 0, byte_3, byte_1.length, byte_2.length); retour byte_3; } / * Entrée une chaîne (hex eg: ff) sorties vers Hex Byte [], notez que l'entrée est une chaîne HEX minuscule * / octet public [] hexStringtoByte (String hex) {int len = (hex.length () / 2); octet [] résultat = nouveau octet [len]; char [] achar = hex.tocharArray (); pour (int i = 0; i <len; i ++) {int pos = i * 2; résultat [i] = (byte) (chartoByte (achar [pos]) << 4 | chartoByte (achar [pos + 1])); } //System.out.println(Arrays.Tostring(Result)); Résultat de retour; } octet privé ChartoByte (char c) {// return (byte) "0123456789abcdef" .Indexof (c); return (octet) "0123456789abcdef" .Indexof (c); } / * Entrez une chaîne numérique décimale, une chaîne hexagonale de sortie (2 bits, par exemple: f, sortie 0f) * / string value = "100"; int parseInt = Integer.ParseInt (valeur, 10); String hexString = Integer.tohexString (parseInt); if (hexstring.length () <2) {hexString = '0' + hexstring; } En-tête = en-tête + hexstring; } / * Entrée hex byte [] output hexstring * / public static String bytearraytohexstr (byte [] bytearray) {if (bytearray) == null) {return null; } char [] hexarray = "0123456789abcdef" .toCharArray (); char [] hexchars = nouveau char [bytearray.length * 2]; for (int j = 0; j <bytearray.length; j ++) {int v = bytearray [j] & 0xff; hexchars [j * 2] = hexarray [v >>> 4]; hexchars [j * 2 + 1] = hexarray [v & 0x0f]; } return new String (hexchars); }PS: Jetons un coup d'œil à la conversion de JS en caractères spéciaux dans URL
Soit str = "http% 3a% 2f% 2fxxxxxxxx% 2Findex.php% 2fxxxxxxx% 2fmember% 2fregister% 3frecommend_id% 3d11442% 26id% 3d87"; Fonction Remplacestr (str) {str = str.replace (/% 3a / g, ":"); str = str.replace (/% 2f / g, "/"); str = str.replace (/% 3f / g, "?"); str = str.replace (/% 3d / g, "="); str = str.replace (/% 26 / g, "&"); str = str.replace (/% 3f / g, "?"); str = str.replace (/% 3d / g, "="); str = str.replace (/% 26 / g, "&"); str = str.replace (/% 26 / g, "&"); str = str.replace (/% 2b / g, "+"); str = str.replace (/% 20 / g, ""); str = str.replace (/% 23 / g, "#"); retour STR; } console.log (remplacestr (str)); Résumer
Ce qui précède est la méthode de conversion de l'octet [], de la chaîne, des chaînes hexagonales et d'autres Java que l'éditeur vous a présentés. J'espère que cela vous sera utile. Si vous avez des questions, veuillez me laisser un message et l'éditeur vous répondra à temps. Merci beaucoup pour votre soutien au site Web Wulin.com!