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[] raw)
Convert bytes to (non "0x" prefixed) hexadecimal String
return toHexString(raw, true);
StringtoHexString(byte[] raw)
to Hex String
if (raw == null) {
    return null;
final StringBuilder hex = new StringBuilder(2 * raw.length);
for (final byte b : raw) {
    hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
return hex.toString();
...
StringtoHexString(byte[] src)
to Hex String
StringBuilder stringBuilder = new StringBuilder();
if (src == null || src.length <= 0) {
    return null;
for (int i = 0; i < src.length; i++) {
    int v = src[i] & 0xFF;
    String hv = Integer.toHexString(v);
    if (hv.length() < 2) {
...
StringtoHexString(byte[] v)
Convert an array of bytes to a hex string.
final String HEX_DIGITS = "0123456789abcdef";
StringBuffer sb = new StringBuffer(v.length * 2);
for (int i = 0; i < v.length; i++) {
    int b = v[i] & 0xFF;
    sb.append(HEX_DIGITS.charAt(b >>> 4)).append(HEX_DIGITS.charAt(b & 0xF));
return sb.toString();
StringtoHexString(byte[] v)
Convert a byte array to a hex string
StringBuffer sb = new StringBuffer();
byte n1, n2;
for (int c = 0; c < v.length; c++) {
    n1 = (byte) ((v[c] < 0 ? -v[c] + 127 : v[c]) / 0x10);
    n2 = (byte) ((v[c] < 0 ? -v[c] + 127 : v[c]) % 0x10);
    sb.append(n1 >= 0xA ? (char) (n1 - 0xA + 'a') : (char) (n1 + '0'));
    sb.append(n2 >= 0xA ? (char) (n2 - 0xA + 'a') : (char) (n2 + '0'));
return sb.toString();
StringtoHexString(byte[] val)
to Hex String
return toHexString(val, 0, val.length);
StringtoHexString(byte[] value)
to Hex String
return toHexString(value, DEFAULT_HEX_DELIMITER);
StringtoHexString(byte[] value)
to Hex String
String newString = "";
for (int i = 0; i < value.length; i++) {
    byte b = value[i];
    String str = Integer.toHexString(b);
    if (str.length() > 2) {
        str = str.substring(str.length() - 2);
    if (str.length() < 2) {
...
StringtoHexString(byte[] value, int startOffset, int maxLength, boolean uppercase, char separator)
to Hex String
if (maxLength == -1 || startOffset + maxLength > value.length) {
    maxLength = value.length - startOffset;
StringBuffer r = new StringBuffer(maxLength * (separator == -1 ? 2 : 3));
for (int i = 0; i < maxLength; i++) {
    if (i > 0 && separator != 0) {
        r.append(separator);
    String t = Integer.toHexString(value[i + startOffset] & 0xFF);
    if (t.length() == 1) {
        t = "0" + t;
    if (uppercase) {
        t = t.toUpperCase();
    r.append(t);
return r.toString();
StringtoHexString(char c)
to Hex String
if (c > 127) {
    throw new IllegalArgumentException("Unsupported char [" + c + "].");
String s = Integer.toHexString(c);
if (s.length() == 1)
    return '0' + s;
else
    return s;
...