Java tutorial
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static String longToHex(long l) { return byteArrayToHex(BigInteger.valueOf(l).toByteArray(), null); } public static String byteArrayToHex(byte[] a) { return byteArrayToHex(a, null); } public static String byteArrayToHex(byte[] a, String divider) { StringBuilder sb = new StringBuilder(a.length * 2); boolean d = false; for (byte b : a) { sb.append(String.format("%02x", b & 0xff)); if (d && divider != null) { sb.append(divider); } d = !d; } return sb.toString(); } }