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

StringtoHexString(final int i)
to Hex String
return "0x" + Integer.toHexString(i);
StringtoHexString(final int value)
Returns a string representation of the integer argument as an unsigned integer in base 16.
return "0x" + Integer.toHexString(value).toUpperCase();
StringtoHexString(final long num, final char paddingChar, int min, int max)

Internal use.

StringBuffer sb = new StringBuffer(Long.toHexString(num));
if (max < min) {
    return sb.toString();
while (sb.length() < max) {
    sb.insert(0, paddingChar);
return sb.substring(0, min);
...
StringtoHexString(int b)
to Hex String
return "" + toHexChar(b >> 4) + toHexChar(b);
StringtoHexString(int b)
Returns a hex string representation of a 8 bit integer.
char[] digits = new char[2];
b = b & 255;
digits[0] = hexDigits[b / 0x10];
digits[1] = hexDigits[b % 0x10];
return new String(digits);
StringtoHexString(int bits, int value)
to Hex String
if (bits < 32)
    value &= (1 << bits) - 1;
String ret = Integer.toHexString(value);
int len = (bits + 3) / 4;
while (ret.length() < len)
    ret = "0" + ret;
if (ret.length() > len)
    ret = ret.substring(ret.length() - len);
...
StringtoHexString(int decimal, int stringLength)
Converts a decimal value to a hexadecimal string represention of the specified length.
return String.format("%0" + stringLength + "X", decimal);
StringtoHexString(int decimal, int stringLength)
Converts a decimal value to a hexadecimal string represention of the specified length.
StringBuilder sb = new StringBuilder(stringLength);
String hexVal = Integer.toHexString(decimal).toUpperCase();
int nofZeros = stringLength - hexVal.length();
for (int i = 0; i < nofZeros; i++) {
    sb.append('0');
sb.append(hexVal);
return sb.toString();
...
StringtoHexString(int i)
to Hex String
final String zeroes = "0000000";
final String s = Integer.toHexString(i).toUpperCase();
if (s.length() < 8)
    return zeroes.substring(s.length() - 1) + s;
else
    return s;
StringtoHexString(int i)
convert an integer to a 2-digit hex string.
String s = Integer.toHexString(i);
while (s.length() < 2) {
    s = "0" + s;
return s;