Java Utililty Methods Decimal to Hex

List of utility methods to do Decimal to Hex

Description

The list of methods to do Decimal to Hex are organized into topic(s).

Method

Stringdec2hex(int dec)
dechex
String s = "";
s = Integer.toHexString(dec).toUpperCase();
if (s.length() % 2 != 0) {
    s = padleft(s, s.length() + 1, '0');
return s;
Stringdecimal2hex(int d)
decimalhex
if (d == 0)
    return "0";
StringBuilder hex = new StringBuilder();
while (d > 0) {
    int digit = d % 16;
    hex.insert(0, digits.charAt(digit));
    d = d / 16;
return hex.toString();
StringdecimalToHex(int n)
Returns the hexadecimal representation of the positive decimal number n.
A two digit representation is provided by this function always.
assert (n >= 0);
String invHexRepr = "";
String hexRepr = "";
String[] digits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
while (n >= 16) {
    int remainder = n % 16;
    invHexRepr = invHexRepr + digits[remainder];
    n = n / 16;
...
chardecimalToHexa(final int d)
decimal To Hexa
return HEXA_DIGITS.charAt(d);