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

StringtoHex(int val)
to Hex
char[] ch8 = new char[8];
for (int i = 8; --i >= 0; val >>= 4) {
    ch8[i] = HEX_DIGIT[val & 0xf];
return String.valueOf(ch8);
StringtoHex(int val)
Converts one int to a hexadecimal ASCII string.
int val1, val2;
val1 = (val >> 4) & 0x0F;
val2 = (val & 0x0F);
return ("" + HEX_DIGIT[val1] + HEX_DIGIT[val2]);
StringtoHEX(int value)
to HEX
return toHEX(value, 4);
chartoHex(int value)
Returns the hexidecimal character representation for an integer.
return HEX_DIGITS[(value & 0xF)];
StringtoHex(int value)
Formats integer value to hex string.
return "0x" + Integer.toHexString(value);
StringtoHex(int value, int bits)
Conversion pixel to HEX value
String hex = Integer.toHexString(value);
int padLen = 4 - hex.length();
if (bits == 0) {
    padLen = 2 - hex.length();
for (int i = 0; i < padLen; i++) {
    hex = "0" + hex;
hex = "0x" + hex;
return hex;
StringtoHex(int value, int length)
to Hex
return toHex(value, length, false);
StringtoHex(int value, int length)
to Hex
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
StringBuffer buffer = new StringBuffer(length);
int shift = length - 1 << 2;
for (int i = -1; ++i < length;) {
    buffer.append(hexDigits[value >> shift & 0xf]);
    value <<= 4;
return buffer.toString();
...
StringtoHex(int value, int minNumOfDigits)
to Hex
String hexString = Integer.toHexString(value);
while (hexString.length() < minNumOfDigits)
    hexString = "0" + hexString;
return "0x" + hexString.toUpperCase();
StringtoHex(long i)
to Hex
return toHex(i, 2, false);