Convert a byte array to a hex string.

@param b The byte array
@return The hex String
507791
public static String toHexString(byte[] b) {
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (byte aByte : b) {
            // look up high nibble char
            sb.append(hexChar[(aByte & 0xf0) >>> 4]);

            // look up low nibble char
            sb.append(hexChar[aByte & 0x0f]);
        }
        return sb.toString();
    }
339896
public static String toStringBinary(final byte [] b, int off, int len) {
    StringBuilder result = new StringBuilder();
    try {
      String first = new String(b, off, len, "ISO-8859-1");
      for (int i = 0; i < first.length(); ++i) {
        int ch = first.charAt(i) & 0xFF;
        if ((ch >= '0' && ch <= '9')
            || (ch >= 'A' && ch <= 'Z')
            || (ch >= 'a' && ch <= 'z')
            || " `~!@#$%^&*()-_=+[]{}\\|;:'\",.<>/?".indexOf(ch) >= 0) {
          result.append(first.charAt(i));
        } else {
          result.append(String.format("\\x%02X", ch));
        }
      }
    } catch (UnsupportedEncodingException e) {
    }
    return result.toString();
  }
1009266
public static String byteArrayToNumString(byte[] b) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < b.length; i++) {
			sb.append(byteToNumString(b[i]));
		}
		return new String(sb);
	}
803130
public String toHexString() {
        return Integer.toHexString(r) + Integer.toHexString(g) + Integer.toHexString(b);
    }
659862
public static byte[] hex2byte(String hex) {
		byte[] ret = new byte[8];
		byte[] tmp = hex.getBytes();
		for (int i = 0; i < 8; i++) {
			ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
		}
		return ret;
	}
992722
public static byte[] asByteArray(String hex) {
        byte[] bts = new byte[hex.length() / 2];
        for (int i = 0; i < bts.length; i++) {
            bts[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2),
                    16);
        }

        return bts;
    }
201393
private static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            int v = bytes[i] & 0xFF;
            hexChars[i * 2] = hexArray[v >>> 4];
            hexChars[i * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }
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();

    }
587514
private static byte convertHexDigit( final byte b )
    {
        if ( ( b >= '0' ) && ( b <= '9' ) )
        {
            return (byte) ( b - '0' );
        }
        if ( ( b >= 'a' ) && ( b <= 'f' ) )
        {
            return (byte) ( b - 'a' + 10 );
        }
        if ( ( b >= 'A' ) && ( b <= 'F' ) )
        {
            return (byte) ( b - 'A' + 10 );
        }
        return 0;
    }
893090
public static String byteArrayToString(byte[] b) {
       final int l = b.length/2;
       if (l*2 != b.length) throw new IllegalArgumentException();
       StringBuffer result = new StringBuffer(l);
       int o = 0;
       for (int i = 0; i < l; i++)
       {
           int i1 = b[o++] & 0xff;
           int i2 = b[o++] & 0xff;
           i2 = i2 << 8;
           i1 = i1 | i2;
           result.append((char)i1);
       }
       return (result.toString());
    }
1044489
public static String byteToHex(byte b[]) {

        int    len = b.length;
        char[] s   = new char[len * 2];

        for (int i = 0, j = 0; i < len; i++) {
            int c = ((int) b[i]) & 0xff;

            s[j++] = HEXCHAR[c >> 4 & 0xf];
            s[j++] = HEXCHAR[c & 0xf];
        }

        return new String(s);
    }
676516
@Nonnull
    public static String toHex(@Nonnull final byte[] bytes) {
        StringBuilder buf = new StringBuilder(bytes.length * 2);
        for (byte b : bytes) {
            String hexDigits = Integer.toHexString((int) b & 0x00ff);
            if (hexDigits.length() == 1) {
                buf.append('0');
            }
            buf.append(hexDigits);
        }
        return buf.toString();
    }
662975
public static String bin2hex(final byte[] b)
    {
        if (b == null)
        {
            return "";
        }
        StringBuffer sb = new StringBuffer(2 * b.length);
        for (int i = 0; i < b.length; i++)
        {
            int v = (256 + b[i]) % 256;
            sb.append(hex.charAt((v / 16) & 15));
            sb.append(hex.charAt((v % 16) & 15));
        }
        return sb.toString();
    }
498470
public String toHexString() {
    final StringBuilder buf = new StringBuilder(24);

    for (final byte b : toByteArray()) {
      buf.append(String.format("%02x", b & 0xff));
    }

    return buf.toString();
  }
532902
public static String toHex(byte b) {
    final char[] string = { hexDigits[(b >> 4) & 0x0f], hexDigits[b & 0x0f] };
    return new String(string);
  }
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);
  }
621767
public static String toHexString(byte in[]) {
		if(in == null || in.length <= 0) {
			return null;
		}

		int i = 0;
		byte ch = 0x00;
		String pseudo[] = {
				"0", "1", "2", "3",
				"4", "5", "6", "7",
				"8", "9", "A", "B",
				"C", "D", "E", "F"
		};

		StringBuffer out = new StringBuffer(in.length * 2);
		while(i < in.length) {
			ch = (byte)(in[i] & 0xF0);		// Strip off high nibble
			ch = (byte)(ch >>> 4);			// shift the bits down
			ch = (byte)(ch & 0x0F);			// must do this is high order bit is on!
			out.append(pseudo[(int)ch]);	// convert the nibble to a String Character
			ch = (byte)(in[i] & 0x0F);		// Strip off low nibble 
			out.append(pseudo[(int)ch]);	// convert the nibble to a String Character
			out.append(' ');
			i++;
		}

		return new String(out);
	}