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

StringtoHexa(byte[] bb)
to Hexa
char[] ret = new char[bb.length * 2];
for (int i = 0; i < bb.length; i++) {
    ret[i * 2] = HEXA_CHARS[((bb[i] & 0xF0) >> 4)];
    ret[i * 2 + 1] = HEXA_CHARS[((bb[i] & 0x0F))];
return new String(ret);
StringtoHexAddress(long address)
to Hex Address
return "0x" + Long.toHexString(address).toUpperCase();
StringtoHexaDecimal(byte[] bytesToConvert)
to Hexa Decimal
final char[] hexCharactersAsArray = "0123456789ABCDEF".toCharArray();
final char[] convertedHexCharsArray = new char[bytesToConvert.length * 2];
for (int j = 0; j < bytesToConvert.length; j++) {
    final int v = bytesToConvert[j] & 0xFF;
    convertedHexCharsArray[j * 2] = hexCharactersAsArray[v >>> 4];
    convertedHexCharsArray[j * 2 + 1] = hexCharactersAsArray[v & 0x0F];
return new String(convertedHexCharsArray);
...
StringtoHexadecimal(byte[] digest)
to Hexadecimal
String hash = "";
for (byte aux : digest) {
    int b = aux & 0xff;
    if (Integer.toHexString(b).length() == 1)
        hash += "0";
    hash += Integer.toHexString(b);
return hash;
...
StringtoHexadecimal(byte[] digest)
Convierte un arreglo de bytes a String usando valores hexadecimales
String hash = "";
for (byte aux : digest) {
    int b = aux & 0xff;
    if (Integer.toHexString(b).length() == 1)
        hash += "0";
    hash += Integer.toHexString(b);
return hash;
...
StringtoHexadecimal(final byte[] array)
Convert a byte array to hexadecimal representation
final int length = array.length;
final char[] chars = new char[length * 2];
int indexWrite = 0;
int b;
for (int indexRead = 0; indexRead < length; indexRead++) {
    b = array[indexRead] & 0xFF;
    chars[indexWrite++] = Integer.toHexString((b >> 4) & 0xF).charAt(0);
    chars[indexWrite++] = Integer.toHexString(b & 0xF).charAt(0);
...
StringtoHexadecimal(final byte[] in)
to Hexadecimal
return toHexadecimal(in, 0, in.length);
StringtoHexadecimal(final byte[] message)
to Hexadecimal
if (message == null) {
    return null;
final StringBuffer buffer = new StringBuffer();
for (int i = 0; i < message.length; i++) {
    int curByte = message[i] & 0xff;
    buffer.append(hexDigits[(curByte >> 4)]);
    buffer.append(hexDigits[curByte & 0xf]);
...
StringtoHexadecimealString(byte[] data, int length, boolean uppercase)
to Hexadecimeal String
StringBuffer bff = new StringBuffer();
for (int i = data.length; i < length; i++)
    bff.append("00");
for (byte b : data)
    bff.append(String.format("%02" + (uppercase ? "X" : "x"), b));
return bff.toString();
StringtoHexArray(byte[] binary)
Turns the binary array to a hexadecimal string.
StringBuilder result;
result = new StringBuilder();
for (byte b : binary)
    result.append(toHex(b));
return result.toString();