@Test public void testBytesToHexString() throws UnsupportedEncodingException { String str = "中文"; byte[] uft8_bytes = str.getBytes(Opslab.UTF_8); String utf8_hexStr = ConvertUtil.bytesToHexString(uft8_bytes); System.out.println("UTF-8 BYTE:" + Arrays.toString(uft8_bytes)); System.out.println("UTF-8 HEX: " + utf8_hexStr); byte[] gbk_bytes = str.getBytes(Opslab.GBK); String gbk_hexStr = ConvertUtil.bytesToHexString(str.getBytes(Opslab.GBK)); System.out.println("GBK BYTE:" + Arrays.toString(gbk_bytes)); System.out.println("GBK HEX: " + gbk_hexStr); System.out.println(new String(uft8_bytes)); System.out.println(new String(gbk_bytes, Opslab.GBK)); }
public final static String bytesToHexString(byte[] bytes) { String result = ""; String hex; for (byte b : bytes) { hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4)); hex += String.valueOf(hexStr.charAt(b & 0x0F)); result += hex + " "; } return result; }
ConvertUtil { public final static String bytesToHexString(byte[] bytes) { String result = ""; String hex; for (byte b : bytes) { hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4)); hex += String.valueOf(hexStr.charAt(b & 0x0F)); result += hex + " "; } return result; } }
ConvertUtil { public final static String bytesToHexString(byte[] bytes) { String result = ""; String hex; for (byte b : bytes) { hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4)); hex += String.valueOf(hexStr.charAt(b & 0x0F)); result += hex + " "; } return result; }  }
ConvertUtil { public final static String bytesToHexString(byte[] bytes) { String result = ""; String hex; for (byte b : bytes) { hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4)); hex += String.valueOf(hexStr.charAt(b & 0x0F)); result += hex + " "; } return result; }  final static byte[] shortToByte(short number); final static short byteToShort(byte[] b); final static byte[] intToByte(int i); final static byte[] intToByte(int[] arr); final static byte[] encodeBytes(byte[] source, char split); final static char[] bytesToChars(byte[] bytes); final static int bytesToInt(byte[] bytes); final static byte[] longToByte(long number); final static long byteToLong(byte[] b); final static String byteToBinary(byte src); final static String hexStringtoBinarg(String hexStr); final static String bytesToHexString(byte[] bytes); final static byte[] hexStringToByte(String hexString); }
ConvertUtil { public final static String bytesToHexString(byte[] bytes) { String result = ""; String hex; for (byte b : bytes) { hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4)); hex += String.valueOf(hexStr.charAt(b & 0x0F)); result += hex + " "; } return result; }  final static byte[] shortToByte(short number); final static short byteToShort(byte[] b); final static byte[] intToByte(int i); final static byte[] intToByte(int[] arr); final static byte[] encodeBytes(byte[] source, char split); final static char[] bytesToChars(byte[] bytes); final static int bytesToInt(byte[] bytes); final static byte[] longToByte(long number); final static long byteToLong(byte[] b); final static String byteToBinary(byte src); final static String hexStringtoBinarg(String hexStr); final static String bytesToHexString(byte[] bytes); final static byte[] hexStringToByte(String hexString);  }