Java tutorial
//package com.java2s; public class Main { public static String encodeHex(int integer) { String hexSTR = Long.toString(integer & 0xffffffff, 16); String returnStr = "00000000"; int valid = returnStr.length() - hexSTR.length(); if (valid > 0) { returnStr = returnStr.substring(0, valid) + hexSTR; } else { returnStr = hexSTR; } return returnStr; } }