16 binding and string conversion

zhaozj2021-02-16  111

Public class util {public util () {}

/ ** * Print the specified byte array to the console * @Param hint string * @Param b byte [] * @return void * / public static void printHexString (String Hint, Byte [] b) { System.out.print (hint); for (int i = 0; i

/ ** * * @Param b byte [] * @Return string * / public static string bytes2HexString (byte [] b) {string ret = ""; for (int i = 0; i

/ ** * Combine two ASCII characters into one byte; * such as "EF" -> 0xef * @Param src0 byte * @Return Byte * / public static Byte Unitebytes (Byte SRC0, BYTE SRC1 ) {Byte _b0 = byte.decode ("0x" new string (new byte [] {src0}). Bytevalue (); _B0 = (byte) (_ b0 << 4); byte _b1 = byte.decode (" 0x " new string (new byte [] {src1}). Bytevalue (); Byte Ret = (Byte) (_ b0 ^ _b1); return ret;}

/ ** * Take the specified string SRC to convert to a 16-way form * such as: "2B44EFD9" -> Byte [] {0x2b, 0x44, 0xef, 0x2b, 0x44, 0xef, 0xd9} * @Param src string * @ @Param src string * @ Return Byte [] * / public static Byte [] HexString2Bytes (String src) {byte [] Ret = new byte [8]; byte [] TMP = src.getbytes (); for (int i = 0; i <8; i ) {RET [i] = unitebytes (TMP [i * 2], TMP [i * 2 1]);} return ret;}}

转载请注明原文地址:https://www.9cbs.com/read-14567.html

New Post(0)