This article turns from: http://franksinger.iteye.com/blog/614540
In Java, byte is used in binary notation to occupy 8 bits, and we know that each character of the 16 binary needs to be represented by 4-bit bits (23 + 22 + 21 + 20 = 15), so we can convert each byte to two corresponding 16 characters. That is, the high 4 bits of byte and the lower 4 bits are converted to the corresponding 16-character H and L and combined to get the result of the byte conversion to the 16 string, new String (H) + new String (L). That is, byte in hexadecimal notation only occupies 2 digits.
In the same way, the opposite conversion converts two 16 characters into a byte, as in principle.
Based on the above principles, we can convert the byte[] array to a 16 binary string, and of course we can convert the 16 string into a byte[] array.
/**
* convert byte[] to hex string. Here we can convert byte to int and then use integer.tohexstring ( int) to convert to a 16 binary string. * @param src byte[] data * @return hex String */ public static string bytestohexstring ( BYTE[]&NBSP;SRC) { StringBuilder stringBuilder = new StringBuilder (""); if (src == null | | src.length <= 0) { return null;  } for int i = 0; i < src.length; i++) { int v = src[i] & 0xFF; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; string hv = integer.tohexstring (v); if (Hv.length () < 2) { stringbuilder.append (0); } stringbuilder.append (HV);   return stringbuilder.tostring (); } /** * Convert hex string to byte[] * @param hexString the hex string * @return byte[] */ public static byte[] hexstringtobytes (string hexstring) { if (hexstring == null | | hexstring.equals ("")) { return null; &NBSP;&NBSP} hexstring = hexstring.touppercase (); int length = hexstring.length () / 2; char[] hexchars = hexstring.tochararray (); byte[] d = new byte[length]; for (int i = 0; i < length; i++ ) { int pos = i * 2; d[i] = (Byte) (Chartobyte hexchars[ POS]) << 4 | chartobyte (hexchars[pos + 1]); } return d; } /** * Convert char to byte * @ param c char * @return byte */