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[] byteArray, int offset, int size)
to Hex String
StringBuilder builder = new StringBuilder();
for (int i = 0; i < size; i++) {
    if (i > 0)
        builder.append(' ');
    builder.append(String.format("%02X", byteArray[offset + i]));
return builder.toString();
StringtoHexString(byte[] byteArray, String delim)
to Hex String
if (delim == null) {
    delim = "";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < byteArray.length; i++) {
    if (i > 0) {
        sb.append(delim);
    String hex = Integer.toHexString(byteArray[i] & 0x00ff).toUpperCase();
    if (hex.length() < 2) {
        sb.append("0");
    sb.append(hex);
return sb.toString();
StringtoHexString(byte[] byteDigest)
to Hex String
String temp = "";
int i, len = byteDigest.length;
for (i = 0; i < len; i++) {
    String byteString = Integer.toHexString(byteDigest[i]);
    int iniIndex = byteString.length();
    if (iniIndex == 2)
        temp = temp + byteString;
    else if (iniIndex == 1)
...
StringtoHexString(byte[] bytes)

toHexString.

StringBuilder ret = new StringBuilder(64);
for (byte each : bytes) {
    String hexStr = Integer.toHexString(each >= 0 ? each : (256 + each));
    if (hexStr.length() == 1) {
        ret.append("0");
    ret.append(hexStr);
return ret.toString();
StringtoHexString(byte[] bytes)
to Hex String
if (bytes != null) {
    StringBuilder hexString = new StringBuilder();
    for (byte b : bytes) {
        String hex = Integer.toHexString(b & BYTE_MASK);
        if (hex.length() == 1) {
            hexString.append('0');
        hexString.append(hex);
...
StringtoHexString(byte[] bytes)
Generates a hexadecimal string from an array of bytes.
StringBuffer sb = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    sb.append(toHex(bytes[i] >> 4));
    sb.append(toHex(bytes[i]));
return sb.toString();
StringtoHexString(byte[] bytes)
to Hex String
if (bytes != null) {
    return toHexString(bytes, 0, bytes.length);
} else {
    return null;
StringtoHexString(byte[] bytes)
to Hex String
StringBuilder builder = new StringBuilder();
for (byte b : bytes) {
    builder.append(Integer.toHexString((b >> 4) & 0xf));
    builder.append(Integer.toHexString(b & 0xf));
return builder.toString();
StringtoHexString(byte[] bytes)
Returns a hex string representation of the given byte array.
if (null == bytes) {
    return null;
StringBuilder sb = new StringBuilder(bytes.length << 1);
for (int i = 0; i < bytes.length; ++i) {
    sb.append(hex[(bytes[i] & 0xf0) >> 4]).append(hex[(bytes[i] & 0x0f)]);
return sb.toString();
...
StringtoHexString(byte[] bytes)
Converts the byte array into a string of hexadecimal numbers.
char[] str = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; ++i) {
    byte b = bytes[i];
    int lower = b & 0x0f;
    int upper = (b & 0xf0) >>> 4;
    str[2 * i] = HEX_DIGITS[upper];
    str[2 * i + 1] = HEX_DIGITS[lower];
return new String(str);