Java Utililty Methods Hex Calculate

List of utility methods to do Hex Calculate

Description

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

Method

StringtoHex(int color)
to Hex
String rv = Integer.toHexString(color);
if (color <= 0x0F)
    return "0" + rv;
else
    return rv;
chartoHex(int decimalDigit)
to Hex
return decimalDigit < 10 ? (char) (decimalDigit + '0') : (char) (decimalDigit - 10 + 'A');
StringtoHex(int h, int minDigit)
to Hex
char[] digits = new char[8];
int d = 7;
do {
    digits[d--] = hexDigits[h & 0xf];
    h >>>= 4;
    --minDigit;
} while (h != 0 || minDigit > 0);
return new String(digits, d + 1, 7 - d);
...
chartoHex(int i)
Translates an int into a hex char.
if (i >= 0 && i <= 9)
    return (char) ('0' + i);
if (i >= 10 && i <= 15)
    return (char) ('a' + i - 10);
throw new IllegalArgumentException("bad hex digit selector " + i);
StringtoHex(int i)
to Hex
return "0x" + Integer.toHexString(i);
StringtoHex(int i)
Convert an integer to a hex string.
String str = Integer.toHexString(0xFF & i);
if (str.length() < 2) {
    str = "0" + str;
return str;
StringtoHex(int i, String $default)
to Hex
return i != -1 ? Integer.toHexString(i) : $default;
chartoHex(int myByte)
to Hex
return HEX_DIGITS.charAt(myByte & 0xF);
chartoHex(int n)
to Hex
if ((0 <= n) && (n <= 9)) {
    return (char) ('0' + n);
} else if ((10 <= n) && (n <= 15)) {
    return (char) (A + n);
} else {
    throw new IllegalArgumentException("" + n);
StringtoHex(int n)
to Hex
StringBuilder sb = new StringBuilder();
if (n / 16 == 0) {
    return toHexUtil(n);
} else {
    String t = toHex(n / 16);
    int nn = n % 16;
    sb.append(t).append(toHexUtil(nn));
return sb.toString();