Original link: http://zhidao.baidu.com/link?url=RmLDjr4PtP_ Oue5j2pknzsvlht1k7hcch4-03y7vkxyhj0kawg01ctkhzc2ubvxqshgzl8pp60wbyulp6k15k_
The following 3 methods can convert byte[] to 16 binary strings, optionally one
/* *
* Convert byte[] to hex string. Here we can convert byte to int, then use integer.tohexstring (int)
* To convert into 16 binary strings.
* @param src byte[] Data
* @return Hex string
*/
Public static String bytestohexstring (byte[] 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;
String HV = integer.tohexstring (v);
if (Hv.length () < 2) {
stringbuilder.append (0);
}
stringbuilder.append (HV);
}
return stringbuilder.tostring ();
}
Public static String bytes2hexstring (byte[] b) {
String ret = "";
for (int i = 0; i < b.length; i++) {
String hex = integer.tohexstring (B[i] & 0xFF);
if (hex.length () = = 1) {
hex = "0" + hex;
}
ret + = hex;
}
return ret;
}
Public static String Tohex (byte[] buffer) {
stringbuffer sb = new StringBuffer (Buffer.length * 2);
for (int i = 0; i < buffer.length; i++) {
sb.append (Character.fordigit (Buffer[i &) >> 4, +));
sb.append (Character.fordigit (Buffer[i] &));
}
return sb.tostring ();
}
How to convert the data inside byte[] into a 16 binary string in Java