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(final byte[] bytes)
to Hex
StringBuilder sb = new StringBuilder(bytes.length);
for (int i = 0; i < bytes.length; i++) {
    sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString();
StringtoHex(final byte[] bytes)
to Hex
if (bytes == null) {
    return "";
StringBuffer sb = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; ++i) {
    appendHex(sb, bytes[i]);
return sb.toString();
...
StringtoHex(final byte[] bytes)
to Hex
return toHex(bytes, true);
StringtoHex(final byte[] bytes)
to Hex
final char[] buffer = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
    buffer[i * 2] = hex[(bytes[i] & 0xf0) >> 4];
    buffer[i * 2 + 1] = hex[bytes[i] & 0xf];
return new String(buffer);
Stringtohex(final byte[] bytes)
tohex
final StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    sb.append(String.format("%02X", bytes[i] & UNSIGNED_BYTE_MASK));
return sb.toString();
StringtoHex(final byte[] bytes, final int offset, final int count)
Converts the specified array of bytes into a string of hex characters (low byte first).
if (offset >= bytes.length)
    throw new IllegalArgumentException(
            "Offset is greater than the length (" + offset + " >= " + bytes.length + ").");
final int byteCount = Math.min((bytes.length - offset), count);
final int upperBound = byteCount + offset;
final char[] chars = new char[byteCount * 2];
int charIndex = 0;
for (int i = offset; i < upperBound; i++) {
...
StringtoHex(final byte[] data)
Return the passed in byte array as a hex string.
return toHex(data, data.length);
StringtoHex(final byte[] data)
Convert byte array to hex string
if (data == null) {
    return null;
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.length; i++) {
    sb.append(String.format("%02x", data[i]));
return sb.toString();
...
StringtoHex(final byte[] data)
Converts data to an hexadecimal string
final StringBuffer buf = new StringBuffer();
for (final byte element : data) {
    int halfbyte = (element >>> 4) & 0x0F;
    int two_halfs = 0;
    do {
        if ((0 <= halfbyte) && (halfbyte <= 9)) {
            buf.append((char) ('0' + halfbyte));
        } else {
...
StringtoHex(final byte[] data, final int startPos, final int length)
Returns the hexadecimal representation of a part of a byte array.
StringBuffer b = new StringBuffer();
int endPos = startPos + length;
for (int i = startPos; i < endPos; i++) {
    if (i > 0) {
        b.append(' ');
    int c = data[i];
    b.append(HEX_DIGITS[(c & 0xF0) >> 4]);
...