Java Utililty Methods Integer to Hex

List of utility methods to do Integer to Hex

Description

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

Method

StringintToHexString(int i)
int To Hex String
return Integer.toHexString(i);
StringintToHexString(int num)

Converts the given integer value to hex string.

return toHexString(intToUnsignedLong(num), '0', 8, 8);
StringintToHexString(int number)
Convert integer to hex String.
return Integer.toString(number, 16);
StringintToHexString(int val, int width)
int To Hex String
String str = Integer.toHexString(val);
if (str.length() >= width) {
    return str;
return mZeroes.substring(0, width - str.length()) + str;
StringintToHexString(int value)
Convert an integer value into a hexadecimal representation that is long enough to contain the significant digits.
StringBuffer buffer = new StringBuffer();
int temp = value;
do {
    int index = temp % 16;
    buffer.insert(0, HEX_DIGITS[index]);
    temp = temp / 16;
} while (temp > 0);
return buffer.toString();
...
StringintToHexString(int value, int digits)
Converts a value to a hex string with a fixed number of digits.
String result = Integer.toHexString(value);
for (int i = result.length(); i < digits; i++) {
    result = "0" + result;
if (result.length() > digits) {
    return result.substring(result.length() - digits);
return result;
...
StringintToHexWithPadding(Integer input, Integer max_size)
int To Hex With Padding
if (max_size <= 8) {
    return String.format("%02x", input);
} else if (max_size <= 16) {
    return String.format("%04x", input);
} else {
    return String.format("%08x", input);