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

StringtoHex(byte[] bytes)
to Hex
StringBuffer hexString = new StringBuffer();
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();
StringtoHex(byte[] bytes)
Convert a byte array into its hex string representation.
StringBuilder builder = new StringBuilder(bytes.length * 2);
for (byte b : bytes) {
    try {
        builder.append(Character.forDigit(b >> 4 & 0x0F, 16));
        builder.append(Character.forDigit(b & 0x0F, 16));
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
return builder.toString();
StringtoHex(byte[] bytes)
to Hex
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < bytes.length; i++)
    stringBuffer.append(String.format("%02X", bytes[i]));
return stringBuffer.toString().toLowerCase();
StringtoHex(byte[] bytes)
to Hex
StringBuilder hexBuilder = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
    hexBuilder.append(Character.forDigit((bytes[i] >>> 4) & 0xf, 16));
    hexBuilder.append(Character.forDigit(bytes[i] & 0xf, 16));
return hexBuilder.toString();
StringtoHex(byte[] bytes)
to Hex
StringBuffer sb = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    byte b = bytes[i];
    char c = (char) ((b >> 4) & 0xf);
    if (c > 9)
        c = (char) ((c - 10) + 'a');
    else
        c = (char) (c + '0');
...
StringtoHex(byte[] bytes)
to Hex
if (bytes != null && bytes.length > 0) {
    StringBuilder buff = new StringBuilder(bytes.length << 1);
    String tmp = null;
    for (int i = 0; i < bytes.length; i++) {
        tmp = (Integer.toHexString(bytes[i] & 0xFF));
        if (tmp.length() == 1) {
            buff.append('0');
        buff.append(tmp);
    return buff.toString();
return null;
byte[]toHex(byte[] bytes)
Converts the given byte array to an array of hex characters.
byte[] hex = new byte[2 * bytes.length];
int index = 0;
for (byte b : bytes) {
    int v = b & 0xFF;
    hex[index++] = HEX_CHAR_TABLE[v >>> 4];
    hex[index++] = HEX_CHAR_TABLE[v & 0xF];
return hex;
...
StringtoHex(byte[] bytes)
to Hex
return toHex(bytes, 0, bytes.length);
StringtoHex(byte[] bytes)
to Hex
StringBuilder retString = new StringBuilder();
for (int i = 0; i < bytes.length; ++i) {
    retString.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1));
return retString.toString();
StringtoHex(byte[] bytes)
Convert byte array to HEX format.
StringBuilder sb = new StringBuilder();
sb.append("0x");
for (byte b : bytes) {
    int v = b & 0xFF;
    sb.append(HEX_SOURCE[v >>> 4]).append(HEX_SOURCE[v & 0x0F]);
return sb.toString();