Java binary and 16 binary conversions
/** * @description Convert binary to 16 binary * * @param buf * @return */public static String parsebyte2hexstr (byte buf[]) {stringbuffer sb = new stringbuffer (); for (int i = 0; i < buf.length; i++) {String hex = Integer.tohexstring (Buf[i] & 0xff); if (hex.length () = = 1) {hex = ' 0 ' + hex ; } sb.append (Hex.touppercase ()); } return sb.tostring ();}}
- 16 Binary conversion to binary
/** *@description convert 16 binary to binary * *@param hexstr *@return */PublicStaticByte[]Parsehexstr2byte (String hexstr) {if (Hexstr.length () <1)ReturnNullByte[] result =new byte[hexstr.length ()/2]; Span class= "Hljs-keyword" >for (int i = 0; i < hexstr.length ()/ 2; i++) {int high = Integer.parseint (hexstr.substring (i * 2, I * 2 + 1), 16); int low = Integer.parseint (hexstr.substring (i * 2 + 1, I * 2 + 2), 16); result [I] = (byte) (High * 16 + Low);} return result;}}
Java binary and 16 binary conversions