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

StringintegerToHex(final Object value, final int desimals)
integer To Hex
String str = Long.toString(((Number) value).longValue(), 16).toUpperCase();
if (desimals == 0 || str.length() == zeroes.length()) {
    return str;
return zeroes.substring(0, desimals - str.length()) + str;
StringintegerToHex(final Object value, final int desimals)
integer To Hex
long tmp;
if (value instanceof Byte) {
    tmp = ((Byte) value).byteValue() & 0xFF;
} else if (value instanceof Short) {
    tmp = ((Short) value).shortValue() & 0xFFFF;
} else if (value instanceof Long) {
    tmp = ((Long) value).longValue() & 0xFFFFFFFF;
} else {
...
StringintegerToHex(int val)
integer To Hex
return Integer.toHexString(val).toUpperCase();
StringintegerToHexShort(int value)
integer To Hex Short
return Integer.toHexString(0x10000 | value).substring(1).toUpperCase();
StringintegerToHexString(final int aValue, final int aFieldWidth)
converts an integer to a hex string with leading zeros
final long mask = (long) (Math.pow(16.0, aFieldWidth) - 1L);
StringBuilder sb = new StringBuilder(Long.toHexString(aValue & mask));
int numberOfLeadingZeros = Math.max(0, aFieldWidth - sb.length());
for (; numberOfLeadingZeros > 0; numberOfLeadingZeros--) {
    sb.insert(0, '0');
return sb.toString();
StringintegerToHexString(int value, int minBytes)
Converts the given integer into an hexadecimal string.
if (minBytes <= 0)
    throw new IllegalArgumentException("Minimum number of bytes must be greater than 0.");
String f = String.format("%%0%dX", minBytes * 2);
return String.format(f, value);
StringintToFixedLengthHex(int value, int length)
Takes value and return its HEX value prefixed with zeros .
String str = Integer.toHexString(value);
StringBuilder paddedStr = new StringBuilder();
if (str.length() < length) {
    for (int i = 0; i < length - str.length(); i++)
        paddedStr.append('0');
paddedStr.append(str);
return paddedStr.toString();
...
StringintToFixedLengthHexString(int i, int length)
Converts an integer into a fixed, zero-padded hexadecimal string representation.
String s = Integer.toHexString(i);
String pad = "0";
while (s.length() < length) {
    s = pad.concat(s);
if (s.length() > length) {
    s = s.substring(0, length);
return s.toUpperCase();
StringintToHex(int a)
int To Hex
byte[] b = new byte[4];
intToBytes(a, b, 0);
return bytesToHex(b);
StringintToHex(int i)
Utility method to convert an int into hex, padded to two characters.
String prelim = Integer.toHexString(i);
if (prelim.length() < 2) {
    prelim = "0" + prelim;
return prelim;