Here you can find the source of dec2hex(int dec)
public static String dec2hex(int dec)
//package com.java2s; //License from project: Apache License public class Main { public static String dec2hex(int dec) { String s = ""; s = Integer.toHexString(dec).toUpperCase(); if (s.length() % 2 != 0) { s = padleft(s, s.length() + 1, '0'); }//from www . j av a 2 s . c o m return s; } public static String padleft(String oristr, int len, char alexin) { int strlen = oristr.length(); String str = ""; if (strlen < len) { for (int i = 0; i < len - strlen; i++) { str = str + alexin; } } str = str + oristr; return str; } }