@Test public void byte2hex() { String s = "5"; try { CodecUtils.hex2byte(s); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IllegalArgumentException); } s = "567400075b6f626a65"; byte[] bs = CodecUtils.hex2byte(s); Assert.assertTrue(s.equalsIgnoreCase(CodecUtils.byte2hex(bs))); }
public static String byte2hex(byte[] bytes) { StringBuilder hs = new StringBuilder(); String stmp; for (int n = 0; bytes != null && n < bytes.length; n++) { stmp = Integer.toHexString(bytes[n] & 0XFF); if (stmp.length() == 1) { hs.append('0'); } hs.append(stmp); } return hs.toString().toUpperCase(); }
CodecUtils { public static String byte2hex(byte[] bytes) { StringBuilder hs = new StringBuilder(); String stmp; for (int n = 0; bytes != null && n < bytes.length; n++) { stmp = Integer.toHexString(bytes[n] & 0XFF); if (stmp.length() == 1) { hs.append('0'); } hs.append(stmp); } return hs.toString().toUpperCase(); } }
CodecUtils { public static String byte2hex(byte[] bytes) { StringBuilder hs = new StringBuilder(); String stmp; for (int n = 0; bytes != null && n < bytes.length; n++) { stmp = Integer.toHexString(bytes[n] & 0XFF); if (stmp.length() == 1) { hs.append('0'); } hs.append(stmp); } return hs.toString().toUpperCase(); }  }
CodecUtils { public static String byte2hex(byte[] bytes) { StringBuilder hs = new StringBuilder(); String stmp; for (int n = 0; bytes != null && n < bytes.length; n++) { stmp = Integer.toHexString(bytes[n] & 0XFF); if (stmp.length() == 1) { hs.append('0'); } hs.append(stmp); } return hs.toString().toUpperCase(); }  static byte[] intToBytes(int num); static int bytesToInt(byte[] ary); static byte[] short2bytes(short num); static byte[] copyOf(byte[] src, int length); static byte[] parseHigh4Low4Bytes(byte b); static byte buildHigh4Low4Bytes(byte high4, byte low4); static byte[] parseHigh2Low6Bytes(byte b); static byte buildHigh2Low6Bytes(byte high2, byte low6); static String byteToBits(byte b); static byte bitsToByte(String bits); static boolean startsWith(byte[] bs, byte[] head); static boolean[] byte2Booleans(byte b); static byte booleansToByte(boolean[] array); static String byte2hex(byte[] bytes); static byte[] hex2byte(String str); static boolean getBooleanFromByte(byte modifiers, int i); static byte setBooleanToByte(byte modifiers, int i, boolean bool); static void flatCopyTo(String prefix, Map<String, Object> sourceMap,
                                  Map<String, String> dstMap); static void treeCopyTo(String prefix, Map<String, String> sourceMap,
                                  Map<String, String> dstMap, boolean remove); }
CodecUtils { public static String byte2hex(byte[] bytes) { StringBuilder hs = new StringBuilder(); String stmp; for (int n = 0; bytes != null && n < bytes.length; n++) { stmp = Integer.toHexString(bytes[n] & 0XFF); if (stmp.length() == 1) { hs.append('0'); } hs.append(stmp); } return hs.toString().toUpperCase(); }  static byte[] intToBytes(int num); static int bytesToInt(byte[] ary); static byte[] short2bytes(short num); static byte[] copyOf(byte[] src, int length); static byte[] parseHigh4Low4Bytes(byte b); static byte buildHigh4Low4Bytes(byte high4, byte low4); static byte[] parseHigh2Low6Bytes(byte b); static byte buildHigh2Low6Bytes(byte high2, byte low6); static String byteToBits(byte b); static byte bitsToByte(String bits); static boolean startsWith(byte[] bs, byte[] head); static boolean[] byte2Booleans(byte b); static byte booleansToByte(boolean[] array); static String byte2hex(byte[] bytes); static byte[] hex2byte(String str); static boolean getBooleanFromByte(byte modifiers, int i); static byte setBooleanToByte(byte modifiers, int i, boolean bool); static void flatCopyTo(String prefix, Map<String, Object> sourceMap,
                                  Map<String, String> dstMap); static void treeCopyTo(String prefix, Map<String, String> sourceMap,
                                  Map<String, String> dstMap, boolean remove); static final Object[] EMPTY_OBJECT_ARRAY; static final Class<?>[] EMPTY_CLASS_ARRAY; }