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

StringintToHex(int i)
Convert an int to a hex representation.
return Integer.toHexString(i);
StringintToHex(int i)
int To Hex
return String.format("0x%08X", i);
StringIntToHex(int i, int length)
Int To Hex
String temp = Integer.toHexString(i);
while (temp.length() < length * 2) {
    temp = "0" + temp;
return temp;
StringintToHex(int id)
int To Hex
if (id < 0x10) {
    return "0" + Integer.toHexString(id);
} else {
    return Integer.toHexString(id);
StringintToHex(int num)
Int to hex.
char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
int i1 = num / 16;
int i2 = num % 16;
StringBuffer ret = new StringBuffer();
ret.append(chars[i1]);
ret.append(chars[i2]);
return ret.toString();
StringintToHex(int val)
Converts an int to a hex String.
String hex = Integer.toHexString(val);
if (hex.length() >= 8) {
    return hex.substring(hex.length() - 8);
return String.format("%8s", hex).replace(' ', '0');
StringintToHex(int val, char delim)
int To Hex
byte[] bytes = new byte[4];
for (int i = 3; i >= 0; i -= 1) {
    bytes[3 - i] = (byte) ((val >>> (i * 8)) & 0xFF);
return bytesToHex(bytes, delim);
StringBufferintToHex(int val, StringBuffer sb)
int To Hex
sb.append(HEX_DIGITS[(val >> 28) & 0xf]);
sb.append(HEX_DIGITS[(val >> 24) & 0xf]);
sb.append(HEX_DIGITS[(val >> 20) & 0xf]);
sb.append(HEX_DIGITS[(val >> 16) & 0xf]);
sb.append(HEX_DIGITS[(val >> 12) & 0xf]);
sb.append(HEX_DIGITS[(val >> 8) & 0xf]);
sb.append(HEX_DIGITS[(val >> 4) & 0xf]);
sb.append(HEX_DIGITS[val & 0xf]);
...
StringintTohex2(int value)
int Tohex
char hex2[] = { Character.forDigit((value >> 4) & 0x0F, 16), Character.forDigit(value & 0x0F, 16) };
String hex2Str = new String(hex2);
return hex2Str.toUpperCase();
StringintToHex8(int value)
int To Hex
return String.format("%08X", value);