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 b[])
Byte array to Hex string
StringBuilder sb = new StringBuilder(b.length * 2);
for (int i = 0; i < b.length; i++) {
    sb.append(hexChar[(b[i] & 0xf0) >>> 4]);
    sb.append(hexChar[b[i] & 0xf]);
return sb.toString();
StringtoHexString(byte buffer[])
to Hex String
StringBuilder content = new StringBuilder(buffer.length * 2);
for (int i = 0; i < buffer.length; i++) {
    content.append(Character.forDigit((buffer[i] & 240) >> 4, 16));
    content.append(Character.forDigit(buffer[i] & 15, 16));
return content.toString();
StringtoHexString(byte buffer[])

Return the HEX representation of an array of bytes.

char output[] = new char[buffer.length * 2];
int position = 0;
for (int x = 0; x < buffer.length; x++) {
    output[position++] = toHexDigit(buffer[x] >> 4);
    output[position++] = toHexDigit(buffer[x]);
return new String(output);
StringtoHexString(byte bytes[])
Convert byte array to hex string
return toHexString(bytes, "");
StringtoHexString(byte bytes[])
Convert a byte array to its hex encoded representation.
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte aByte : bytes) {
    sb.append(cd(aByte >> 4));
    sb.append(cd(aByte & 0x0f));
return (sb.toString());
StringtoHexString(byte bytes[])
Returns an hexadecimal string representation of the given byte array, where each byte is represented by two hexadecimal characters and padded with a zero if its value is comprised between 0 and 15 (inclusive).
StringBuilder sb = new StringBuilder();
for (byte aByte : bytes) {
    String hexByte = Integer.toHexString(aByte & 0xFF);
    if (hexByte.length() == 1)
        sb.append('0');
    sb.append(hexByte);
return sb.toString();
...
StringtoHexString(byte bytes[])
Convert a collection of bytes from an MD5 hash to a string.
char chars[] = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; ++i) {
    chars[2 * i] = HEXCODE[(bytes[i] & 0xF0) >>> 4];
    chars[2 * i + 1] = HEXCODE[bytes[i] & 0x0F];
return new String(chars);
StringtoHexString(byte bytes[])
Converts the checksum given as an array of bytes into a hex-encoded string.
StringBuffer ret = new StringBuffer();
for (int i = 0; i < bytes.length; ++i) {
    ret.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1));
return ret.toString();
StringtoHexString(byte bytes[])
to Hex String
return toHexString(bytes, 0, bytes.length);
StringtoHexString(byte data[])
to Hex String
return toHexString(data, 0, data.length);