Encodes a byte array into a hex string (hex dump).
@deprecated Please see class HexUtil
771846
@Deprecated
    public static String encodeHex(byte[] data, char delimiter) {
        // the result
        StringBuilder result = new StringBuilder();

        short val = 0;

        // encode each byte into a hex dump
        for (int i = 0; i < data.length; i++) {
            val = decodeUnsigned(data[i]);
            result.append(padLeading(Integer.toHexString((int) val), 2));
            result.append(delimiter);
        }

        // return encoded text
        return result.toString();
    }
261067
private static String getHexString(byte[] bytes) {

        // If null byte array given, return null
        if (bytes == null)
            return null;

        // Create string builder for holding the hex representation,
        // pre-calculating the exact length
        StringBuilder hex = new StringBuilder(2 * bytes.length);

        // Convert each byte into a pair of hex digits
        for (byte b : bytes) {
            hex.append(HEX_CHARS[(b & 0xF0) >> 4])
               .append(HEX_CHARS[ b & 0x0F      ]);
        }

        // Return the string produced
        return hex.toString();

    }
274814
public static String toHex(byte[] bytes) {
		StringBuilder hexString=new StringBuilder();
		for (int i=0; i<bytes.length; i++) {

			String hex=Integer.toHexString(0xFF & bytes[i]);
			if (hex.length() == 1) {
				hexString.append('0');
			}

			hexString.append(hex);
		}

		return hexString.toString();
	}
1163616
def encode(hex)
      leading_zero_bytes = (hex.match(/^([0]+)/) ? $1 : '').size / 2
      int_val = hex.to_i(16)
      base58_val = ''
      while int_val > 0
        int_val, remainder = int_val.divmod(SIZE)
        base58_val = ALPHABET[remainder] + base58_val
      end
      ('1' * leading_zero_bytes) + base58_val
    end
924131
private static String byte2hex(byte b[]) {
		StringBuilder sb = new StringBuilder();
		for (int n = 0; n < b.length; n++) {
			String stmp = Integer.toHexString(b[n] & 0xff);
			if (stmp.length() == 1) {
				// hs = hs + "0" + stmp;
				sb.append("0");
			}
			sb.append(stmp);
			// else {
			// // hs = hs + stmp;
			// }
		}

		return sb.toString().toUpperCase();
	}
224373
static String toHexString(final byte b) {
		String hexString = Integer.toHexString(b & 0xFF);
		if (hexString.length() % 2 != 0) {
			// Pad with 0
			hexString = "0" + hexString;
		}
		return hexString;
	}
720721
public static String hexDecode(final char[] data) {
        try {
            val result = Hex.decodeHex(data);
            return new String(result, StandardCharsets.UTF_8);
        } catch (final Exception e) {
            return null;
        }
    }
21209
static String toHexString(byte[] data) {
    char[] chArray = new char[data.length * 2];
    int pos = 0;
    for (byte b : data) {
      chArray[pos++] = HEX_CHARS[(b >> 4) & 0x0f];
      chArray[pos++] = HEX_CHARS[b & 0x0f];
    }
    return new String(chArray);
  }
444114
public static byte[] hexStringToBytes(String data) {
        if (data == null)
            return EMPTY_BYTE_ARRAY;
        if (data.startsWith("0x"))
            data = data.substring(2);
        return Hex.decode(data);
    }
84516
public static final String bytesToHex(byte[] bs, int off, int length) {
		StringBuffer sb = new StringBuffer(length * 2);
		bytesToHexAppend(bs, off, length, sb);
		return sb.toString();
	}
877211
public static String toHexString(byte b) {
		final char[] out = new char[2];
		out[0] = hexDigits[(0xF0 & b) >>> 4];
		out[1] = hexDigits[0x0F & b];
		return new String(out);
	}
1016096
public static String hexDump(ByteBuf buffer, int fromIndex, int length) {
        return HexUtil.hexDump(buffer, fromIndex, length);
    }
584254
public static String hexDump(String prefix, byte[] data) {
        byte byte_value;

        StringBuffer str = new StringBuffer(data.length * 3);

        str.append(prefix);

        for (int i = 0; i < data.length; i += 16) {
            // dump the header: 00000000:
            String offset = Integer.toHexString(i);

            // "0" left pad offset field so it is always 8 char's long.
            str.append("  ");
            for (int offlen = offset.length(); offlen < 8; offlen++) {
                str.append("0");
            }
            str.append(offset);
            str.append(":");

            // dump hex version of 16 bytes per line.
            for (int j = 0; (j < 16) && ((i + j) < data.length); j++) {
                byte_value = data[i + j];

                // add spaces between every 2 bytes.
                if ((j % 2) == 0) {
                    str.append(" ");
                }

                // dump a single byte.
                byte high_nibble = (byte) ((byte_value & 0xf0) >>> 4);
                byte low_nibble = (byte) (byte_value & 0x0f);

                str.append(HEX_TABLE[high_nibble]);
                str.append(HEX_TABLE[low_nibble]);
            }

            // IF THIS IS THE LAST LINE OF HEX, THEN ADD THIS
            if (i + 16 > data.length) {
                // for debugging purposes, I want the last bytes always padded
                // over so that the ascii portion is correctly positioned
                int last_row_byte_count = data.length % 16;
                int num_bytes_short = 16 - last_row_byte_count;
                // number of spaces to add = (num bytes remaining * 2 spaces per byte) + (7 - (num bytes % 2))
                int num_spaces = (num_bytes_short * 2) + (7 - (last_row_byte_count / 2));
                for (int v = 0; v < num_spaces; v++) {
                    str.append(" ");
                }
            }

            // dump ascii version of 16 bytes
            str.append("  ");

            for (int j = 0; (j < 16) && ((i + j) < data.length); j++) {
                char char_value = (char) data[i + j];

                // RESOLVE (really want isAscii() or isPrintable())
                //if (Character.isLetterOrDigit(char_value))
                if (isPrintableChar(char_value)) {
                    str.append(String.valueOf(char_value));
                } else {
                    str.append(".");
                }
            }

            // new line
            str.append("\n");
        }

        // always trim off the last newline
        str.deleteCharAt(str.length() - 1);

        return (str.toString());
    }
297892
@Override
	public ByteArray encodeAsByteArray() {
		if(message.isEmpty()) return ByteArray.EMPTY_BYTE_ARRAY;

		return new ByteArray(message.getBytes(CHARSET));
	}
199775
public static void dumpHex(StringBuilder s, ByteBuffer buffer) {
		int savePos = buffer.position();
		int line = 0;
		while (buffer.hasRemaining()) {
			s.append(StringUtil.encodeHexaPadding(16L * line)).append(' ');
			int l = buffer.remaining() >= 16 ? 16 : buffer.remaining();
			byte[] b = new byte[l];
			buffer.get(b);
			for (int i = 0; i < 16; ++i) {
				if (b.length <= i) s.append("   ");
				else s.append(StringUtil.encodeHexa(b[i])).append(' ');
			}
			s.append("  ");
			for (int i = 0; i < 16; ++i) {
				if (b.length <= i) s.append(' ');
				else {
					char c = (char)(b[i] & 0xFF);
					if (c < 0x20 || c > 0x7F) c = '.';
					s.append(c);
				}
			}
			s.append("\r\n");
			line++;
		}
		buffer.position(savePos);
	}
1118427
private static char[] encodeHex(byte[] data, char[] toDigits) {
		final int len = data.length;
		final char[] out = new char[len << 1];//len*2
		// two characters from the hex value.
		for (int i = 0, j = 0; i < len; i++) {
			out[j++] = toDigits[(0xF0 & data[i]) >>> 4];// 高位
			out[j++] = toDigits[0x0F & data[i]];// 低位
		}
		return out;
	}
194299
public static String toHexString(byte b) {
    StringBuffer sb = new StringBuffer(4);
    sb.append("0x").append(HEX_CHARS[0x0F & (b >> 4)])
        .append(HEX_CHARS[b & 0x0F]);
    return sb.toString();
  }