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[] bytes)
Returns a string in the hexadecimal format.
if (bytes == null) {
    throw new IllegalArgumentException("byte array must not be null"); 
StringBuilder hex = new StringBuilder(bytes.length * 2);
for (byte aByte : bytes) {
    hex.append(Character.forDigit((aByte & 0XF0) >> 4, 16));
    hex.append(Character.forDigit((aByte & 0X0F), 16));
return hex.toString();
StringtoHexString(byte[] bytes)
to Hex String
StringBuffer result = new StringBuffer();
int length = 0;
for (int i = 0; i < bytes.length; i++) {
    result.append(toHexString(bytes[i]));
    length += 2;
    if (length > 80) {
        result.append("\n");
        length = 0;
...
StringtoHexString(byte[] bytes)
Converts a byte array to a hexadecimal ASCII string.
String str = "";
if (bytes != null) {
    int len = bytes.length;
    for (int i = 0; i < len; i++) {
        str += toHex(bytes[i]);
return str;
...
StringtoHexString(byte[] bytes)
to Hex String
char[] hexArray = "0123456789ABCDEF".toCharArray();
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
    int v = bytes[j] & 0xFF;
    hexChars[j * 2] = hexArray[v >>> 4];
    hexChars[j * 2 + 1] = hexArray[v & 0x0F];
return new String(hexChars);
...
StringtoHexString(byte[] bytes)
to Hex String
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte b : bytes) {
    sb.append(HEX_DIGITS[(b >>> 4) & 0x0f]);
    sb.append(HEX_DIGITS[b & 0x0f]);
return sb.toString();
StringtoHexString(byte[] bytes)
to Hex String
StringBuffer sb = new StringBuffer();
sb.append("0x");
int i;
for (i = 0; i < bytes.length; i++) {
    sb.append(HexChars[(bytes[i] >> 4) & 0xf]);
    sb.append(HexChars[bytes[i] & 0xf]);
return new String(sb);
...
StringtoHexString(byte[] bytes)
Creates a String containing the hexadecimal representation of the given bytes.
return toHexString(bytes, 0, bytes != null ? bytes.length : 0, -1);
StringtoHexString(byte[] bytes)
Returns a string representation of the byte array as a series of hexadecimal characters.
char[] hexString = new char[2 * bytes.length];
int j = 0;
for (int i = 0; i < bytes.length; i++) {
    hexString[j++] = HEX_CHARS[(bytes[i] & 0xF0) >> 4];
    hexString[j++] = HEX_CHARS[bytes[i] & 0x0F];
return new String(hexString);
StringtoHexString(byte[] bytes)
Returns hex view of byte array
char[] hexView = new char[bytes.length * 3];
int i = 0;
for (byte b : bytes) {
    hexView[i++] = hexArray[(b >> 4) & 0x0F];
    hexView[i++] = hexArray[b & 0x0F];
    hexView[i++] = ' ';
return new String(hexView);
...
StringtoHexString(byte[] bytes)

Given an array of bytes, it will return the representation as a string of hex data.

StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
    byte b = bytes[i];
    sb.append(new char[] { HEX_CHARS[(b >> 4) & 0x0f], HEX_CHARS[b & 0x0f] });
return sb.toString();