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(final byte[] data, final String separator)
to Hex
if (data.length == 0) {
    return "";
final StringBuilder sb = new StringBuilder(data.length * (separator.length() + 2) - separator.length());
for (int i = 0; i < data.length; i++) {
    if (i > 0) {
        sb.append(separator);
    sb.append(toHex((data[i] & 0xF0) >> 4));
    sb.append(toHex(data[i] & 0x0F));
return sb.toString();
char[]toHex(final byte[] input)
Converts bytes to hexadecimal characters.
char[] ret = new char[input.length * 2];
for (int i = 0; i < input.length; ++i) {
    int b = 0xFF & input[i];
    ret[i * 2] = HEX_ALPHABET[b >> 4];
    ret[i * 2 + 1] = HEX_ALPHABET[0x0F & b];
return ret;
StringtoHex(final byte[] value)
Converts an array of bytes into a String representing the hexadecimal values of each byte in order.
return (value != null) ? new String(encodeHex(value, false)) : null;
chartoHex(final char a, final int halfbyte)
to Hex
return (char) (halfbyte < 10 ? '0' + halfbyte : a + halfbyte - 10);
inttoHex(final char[] dest, int destPos, final byte[] src, final int srcStart, final int srcLength)
to Hex
for (int i = 0; i < srcLength; i++) {
    int u = src[i] & 255;
    dest[destPos + 1] = digits[u & 0x0F];
    u >>>= 4;
    dest[destPos] = digits[u & 0x0F];
    destPos += 2;
return srcLength << 1;
...
chartoHex(final int i)
To hex.
return HEXADECIMAL_DIGITS[i & 0xF];
StringtoHex(final int value)
Converts the specified integer (in the range 0-255) into a hex string.
final String hex = Integer.toHexString(value);
return (hex.length() < 2 ? "0" : "") + hex;
StringtoHex(final String input)
to Hex
return new String(toHex(input.getBytes()));
chartoHex(int ch)
to Hex
return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);
chartoHex(int ch)
Char value of mark
return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);