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

StringtoHexString(byte[] data)
to Hex String
if (data == null) {
    return null;
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
    r.append(hexCode[(b >> 4) & 0xF]);
    r.append(hexCode[(b & 0xF)]);
return r.toString();
StringtoHexString(byte[] data)
Produces a string with each byte in two-digit hex and no spaces between each byte.
if (data == null) {
    return null;
String s = "";
for (int i = 0; i < data.length; i++) {
    byte b = data[i];
    if ((b >= 0) && (b < 16)) {
        s = s + "0";
...
StringtoHexString(byte[] data)
to Hex String
String hex = "";
for (byte by : data) {
    int b = by & 0xff;
    if (Integer.toHexString(b).length() == 1)
        hex = hex + "0";
    hex = hex + Integer.toHexString(b);
return hex;
...
StringtoHexString(byte[] data)
to Hex String
StringBuilder builder = new StringBuilder();
for (byte b : data) {
    builder.append(b);
return builder.toString();
StringtoHexString(byte[] data, final int offset, final int count)
to Hex String
char[] result = new char[count << 1];
final String hexDigits = "0123456789abcdef";
final int end = offset + count;
for (int i = offset, j = 0; i < end; i++) {
    result[j++] = hexDigits.charAt((data[i] >>> 4) & 0x0F);
    result[j++] = hexDigits.charAt(data[i] & 0x0F);
return new String(result);
...
StringtoHexString(byte[] data, int maxLen)
to Hex String
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < data.length && i < maxLen; i++) {
    sb.append(String.format("0x%02x", data[i]));
    if (i < data.length - 1 && i < maxLen - 1)
        sb.append(" ");
sb.append("]");
return sb.toString();
...
StringtoHexString(byte[] data, int offset, int length)
to Hex String
StringBuilder sb = new StringBuilder();
int l;
if (data.length != length) {
    l = data.length - length;
} else {
    l = length;
for (int i = offset; i < l; i++) {
...
StringtoHexString(byte[] data, int offset, int length)
Convert a byte array to a String with a hexidecimal format.
StringBuilder s = new StringBuilder(length * 2);
int end = offset + length;
for (int i = offset; i < end; i++) {
    int high_nibble = (data[i] & 0xf0) >>> 4;
    int low_nibble = (data[i] & 0x0f);
    s.append(hex_table[high_nibble]);
    s.append(hex_table[low_nibble]);
return s.toString();
StringtoHexString(byte[] data, int start, int len)
to Hex String
StringBuilder buf = new StringBuilder();
for (int i = 0; i < len; i++) {
    int b = data[start + i] & 0xFF;
    if (b < 16) {
        buf.append('0');
    buf.append(Integer.toHexString(b));
return buf.toString();
StringtoHexString(byte[] data, int start, int length)
toHexString - generate a hex string representation of the specified portion of the given array
String hex = "";
int end = start + length;
for (int i = start; i < end; i++) {
    String val = "0" + Integer.toHexString(data[i]);
    hex += val.substring(val.length() - 2);
return hex;