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

StringtoHexHashString(byte[] id)
to Hex Hash String
StringBuilder sb = new StringBuilder(20);
assert (id.length == 20);
for (int i = 0; i < 20; i++) {
    int val = id[i] & 0xff;
    sb.append(HEX_CHARS[val >> 4]);
    sb.append(HEX_CHARS[val & 0xf]);
return sb.toString();
...
StringtoHexLiteral(int v)
to Hex Literal
return "0x" + Integer.toHexString(v);
StringtoHexN(long src, int hexn)
to Hex N
return toHexN(src, hexn, 13);
intToHexNumber(int c)
To Hex Number
if (c >= 'A' && c <= 'Z')
    return 10 + c - 'A';
else if (c >= 'a' && c <= 'z')
    return 10 + c - 'a';
else if (c >= '0' && c <= '9')
    return c - '0';
return -1;
StringtoHexOrNegative(int i)
to Hex Or Negative
return toHex(i, "-1");
StringtoHexPadZero(byte[] bytes)
Convert bytes to hexadecimal representation.
StringBuilder ret = new StringBuilder(bytes.length * 2);
for (byte b : bytes) {
    ret.append(hexChars[(b >> 4) & 0xF]);
    ret.append(hexChars[b & 0xF]);
return ret.toString();
StringtoHexShortString(byte[] bytes)
Returns a String representing the byte[] as a sequence of uppercase hexadecimal characters, starting with "0x".
StringBuffer sb = new StringBuffer("0x");
boolean leadingZeros = true;
if (bytes != null) {
    for (byte b : bytes) {
        if (leadingZeros && b == 0)
            continue;
        leadingZeros = false;
        sb.append(HEX_CHARS[0x0F & (b >> 4)]).append(HEX_CHARS[b & 0x0F]);
...
StringtoHexStr(byte b[])
to Hex Str
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < b.length; i++) {
    String plainText = Integer.toHexString(0xff & b[i]);
    if (plainText.length() < 2)
        plainText = "0" + plainText;
    hexString.append(plainText);
return hexString.toString();
...
StringtoHexStr(byte[] b)
to Hex Str
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < b.length; ++i) {
    buffer.append(toHexStr(b[i]));
return buffer.toString();
StringtoHexStr(byte[] binary)
to Hex Str
if (binary == null) {
    return null;
if (binary.length == 0) {
    return "";
int len = binary.length;
StringBuilder sb = new StringBuilder(len * 2);
...