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

StringasHex(final int value)
as Hex
return "0x" + Integer.toHexString(value);
StringasHex(int i)
as Hex
return asHex(i, true, false, true);
StringasHex(int i, int width)
as Hex
String s = Integer.toHexString(i);
if (s.length() >= width) {
    return s;
StringBuilder sb = new StringBuilder();
for (int chars = width - s.length(); chars > 0; chars--) {
    sb.append('0');
sb.append(s);
return sb.toString();
StringasHex(int val)
Returns a hex string representation of the given int value.
String h = Integer.toHexString(val);
return OX + h;
StringconvertIntArrayToHexString(int[] arr)
Formats a byte array in hex, without the "0x" notation.
StringBuffer strbuf = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
    if (arr[i] > 255) {
        throw new IllegalArgumentException("value in array exceeds one byte: " + arr[i]);
    strbuf.append(padHex(arr[i]));
return strbuf.toString();
...
StringconvertIntToHex(int i)
convert Int To Hex
String rtrn = Integer.toHexString(i);
return rtrn.length() == 1 ? "0" + rtrn : rtrn;
intconvertInttoHexa(int n)
convert int value to hexa
return Integer.valueOf(String.valueOf(n), 16);
Stringint2CharHex(int integer)
int Char Hex
int low = integer & 0xF;
int high = (integer >> 4) & 0xF;
return (Character.toString(hexval[high]) + Character.toString(hexval[low]));
voidint2hex(final int a, final StringBuffer str)
inthex
str.append(Integer.toHexString(a));
Stringint2hex(final int i)
Convert an integer into a hex-string.
String s = Integer.toHexString(i / HEX) + Integer.toHexString(i % HEX);
return s.toUpperCase();