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)
Encode arbitrary byte array as a hex string.
StringBuffer sb = new StringBuffer(2 * b.length);
for (int i = 0; i < b.length; i++)
    sb.append(toHex(b[i]));
return sb.toString();
StringtoHex(byte[] b, int off, int len, String separator)
to Hex
StringBuilder result = new StringBuilder();
for (int i = 0; i < b.length && i < len; i++) {
    result.append(toHex(b[i]));
    if (i != b.length - 1)
        result.append(separator);
return result.toString();
StringtoHEX(byte[] ba)
utility method to convert a byte array to a hexadecimal string.
int length = ba.length;
char[] buf = new char[length * 3];
for (int i = 0, j = 0, k; i < length;) {
    k = ba[i++];
    buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
    buf[j++] = HEX_DIGITS[k & 0x0F];
    buf[j++] = ' ';
return new String(buf);
StringtoHex(byte[] buffer)
Converts an array of bytes into a String representing each byte as an unsigned hex number.
StringBuffer sb = new StringBuffer();
String s = null;
for (int i = 0; i < buffer.length; i++) {
    s = Integer.toHexString((int) buffer[i] & 0xff);
    if (s.length() < 2) {
        sb.append('0');
    sb.append(s);
...
char[]toHex(byte[] buffer)
Render a byte array into a string of hexadecimal numbers.
char[] result = new char[buffer.length * 2];
for (int i = 0; i < buffer.length; i++) {
    result[i << 1] = HEX[(buffer[i] & 0xF0) >>> 4];
    result[(i << 1) + 1] = HEX[buffer[i] & 0x0F];
return result;
StringtoHex(byte[] bytes)
to Hex
return toHex(bytes, 0, bytes.length);
StringtoHex(byte[] bytes)
Converts bytes to hex string
if (bytes == null) {
    return null;
int capacity = bytes.length << 1;
char[] hexChars = new char[capacity];
for (int i = 0, j = 0; i != bytes.length; ++i) {
    int v = bytes[i] & 0xFF;
    hexChars[j++] = HEX_ARRAY[v >>> 4];
...
StringtoHex(byte[] bytes)
to Hex
StringBuilder buf = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
    byte b = bytes[i];
    int fnibble = (b >> 4);
    int snibble = 0x0f & b;
    buf.append(HEX_VALUES[fnibble]);
    buf.append(HEX_VALUES[snibble]);
return buf.toString();
StringtoHex(byte[] bytes)
Converts a byte array into a simple hexadecimal character string.
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int j = 0; j < bytes.length; j++) {
    int v = bytes[j] & 0xFF;
    sb.append(HEX[v >>> 4]).append(HEX[v & 0x0F]);
return sb.toString();
StringtoHex(byte[] bytes)
Converts the specified array of bytes to a hex string.
final char[] string = new char[2 * bytes.length];
int i = 0;
for (byte b : bytes) {
    string[i++] = hexDigits[(b >> 4) & 0x0f];
    string[i++] = hexDigits[b & 0x0f];
return new String(string);