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[] a)
to Hex
char[] result = new char[2 * a.length];
for (int i = 0; i < a.length; i++) {
    int high = (0xF0 & a[i]) >> 4;
    int low = (0x0F & a[i]);
    result[2 * i] = charMap[high];
    result[2 * i + 1] = charMap[low];
return new String(result);
...
voidtoHex(byte[] address, StringBuilder builder)
to Hex
if (address == null || address.length < 4) {
    throw new IllegalArgumentException("address is invalid");
if (builder == null) {
    throw new IllegalArgumentException("builder is invalid");
String hex;
int pos = 0;
...
Stringtohex(byte[] arg)
tohex
String res = "";
String a;
for (int i = 0; i < arg.length; i++) {
    a = Integer.toHexString(((int) arg[i]) & 0xFF);
    if (a.length() == 1)
        a = "0" + a;
    res += a;
return res;
StringtoHex(byte[] arr)
to Hex
StringBuffer str = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
    str.append(hex[(arr[i] >> 4) & 0x0f]);
    str.append(hex[arr[i] & 0x0f]);
return str.toString();
StringtoHex(byte[] array)
Get the hexadecimal representation of a byte array.
return toHex(array, 0, array.length);
StringtoHex(byte[] array, int offset, int length)
to Hex
StringBuilder sb = new StringBuilder(length * 4);
for (int i = 0; i < length; i++) {
    int b = array[offset + i];
    sb.append(String.format("\\x%02X", b & 0xFF));
return sb.toString();
StringtoHex(byte[] b)
to Hex
String out = "";
for (int index = 0; index < b.length; index++) {
    out += "b[" + index + "][" + Integer.toHexString(b[index]) + "]\n";
return out;
StringtoHex(byte[] b)
to Hex
StringBuilder buffer = new StringBuilder(128);
for (byte i : b) {
    buffer.append(toHex(i));
return buffer.toString();
StringtoHex(byte[] b)
Like DataHelper.toHexString but ensures no loss of leading zero bytes
StringBuilder buf = new StringBuilder(40);
for (int i = 0; i < b.length; i++) {
    int bi = b[i] & 0xff;
    if (bi < 16)
        buf.append('0');
    buf.append(Integer.toHexString(bi));
return buf.toString();
...
StringtoHex(byte[] b)
Return a hexadecimal representation of a byte array
char[] buf = new char[b.length * 2];
int j = 0;
int k;
for (byte aB : b) {
    k = aB;
    buf[j++] = HEX[(k >>> 4) & 0x0F];
    buf[j++] = HEX[k & 0x0F];
return new String(buf);