HexEncode { public static String longToHexString(long val) { char[] arr = Long.toHexString(val).toCharArray(); StringBuffer buf = new StringBuffer(); int index = 0; for (; index < 16 - arr.length; index++) { buf.append("0"); if ((index & 0x01) == 1) { buf.append(":"); } } for (int j = 0; j < arr.length; j++) { buf.append(arr[j]); if ((index + j & 0x01) == 1 && j < arr.length - 1) { buf.append(":"); } } return buf.toString(); } private  HexEncode(); static String bytesToHexString(byte[] bytes); static String longToHexString(long val); static byte[] bytesFromHexString(String values); static long stringToLong(String values); static String bytesToHexStringFormat(byte[] bytes);  }
@Test public void testLongToHexString() { long value1 = 12345678L; String str1 = HexEncode.longToHexString(value1); Assert.assertTrue(str1.equals("00:00:00:00:00:bc:61:4e")); long value2 = 98765432L; String str2 = HexEncode.longToHexString(value2); Assert.assertFalse(str2.equals("00:44:33:22:11:bc:61:4e")); }