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(byte b)
to Hex
String st = Integer.toHexString(b);
return (st.length() == 1) ? "0" + st : st;
StringtoHex(byte b)
Renders a given by to nice human readable hex format.
StringBuffer sb = new StringBuffer(4);
sb.append("0x");
int val = b & 0xff;
if (val < 0x10)
    sb.append("0");
sb.append(Integer.toString(val, 16));
return sb.toString();
StringtoHex(byte b)
convert to hex string
return toHex(((long) b) & 0xFFL);
StringtoHex(byte b)
Convert a byte to its hexadecimal representation.
return (new Character(hexDigits[(b & 0xF0) >> 4])).toString() + hexDigits[b & 0x0F];
voidtoHex(byte b, char[] charArray, int from)
Converts a byte value to hexadecimal and put the result in an array.
charArray[from] = c[(b >> 4) & 0x0F];
charArray[from + 1] = c[b & 0x0F];
StringtoHex(byte b, String prefix)
to Hex
return prefix + String.format("%02x", b);
StringtoHex(byte bytes[])
to Hex
StringBuffer buf = new StringBuffer(bytes.length * 2);
int i;
for (i = 0; i < bytes.length; i++) {
    if ((bytes[i] & 0xff) < 0x10) {
        buf.append("0");
    buf.append(Long.toString(bytes[i] & 0xff, 16));
return buf.toString();
StringtoHex(byte data[])
to Hex
char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
StringBuffer result = new StringBuffer(data.length * 2);
for (int i = 0; i < data.length; i++) {
    result.append(hex[(data[i] >> 4) & 0x0f]).append(hex[data[i] & 0x0f]);
return result.toString();
StringtoHex(byte hash[])
to Hex
if (hash == null) {
    return null;
StringBuffer buf = new StringBuffer(hash.length * 2);
int i;
for (i = 0; i < hash.length; i++) {
    if ((hash[i] & 0xff) < 0x10) {
        buf.append("0");
...
bytetoHex(byte in)
to Hex
if (in >= '0' && in <= '9') {
    return (byte) (in - '0');
} else if (in >= 'A' && in <= 'F') {
    return (byte) (in - 'A');
} else if (in >= 'a' && in <= 'f') {
    return (byte) (in - 'a');
return in;
...