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 in[])
to Hex
byte ch = 0x00;
int i = 0;
if (in == null || in.length <= 0)
    return null;
String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
StringBuffer out = new StringBuffer(in.length * 3);
while (i < in.length) {
    ch = (byte) (in[i] & 0xF0); 
...
StringtoHex(byte in[])
Convert a byte[] array to a readable string format.
byte ch = 0x00;
int i = 0;
if (in == null || in.length <= 0)
    return null;
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); 
...
StringtoHex(byte input[])
to Hex
if (input == null)
    return null;
StringBuffer output = new StringBuffer(input.length * 2);
for (int i = 0; i < input.length; i++) {
    int current = input[i] & 0xff;
    if (current < 16)
        output.append("0");
    output.append(Integer.toString(current, 16));
...
chartoHex(byte lowByte)
to Hex
assert (lowByte < 16);
if (lowByte < 10) {
    return (char) ('0' + lowByte);
} else if (lowByte < 16) {
    return (char) ('A' + lowByte - 10);
} else {
    return '?';
StringtoHex(byte n)
to Hex
return table[(n >>> 4) & 0x0F] + table[n & 0x0F];
StringtoHex(byte one)
to Hex
String HEX = "0123456789ABCDEF";
char[] result = new char[2];
result[0] = HEX.charAt((one & 0xf0) >> 4);
result[1] = HEX.charAt(one & 0x0f);
return new String(result);
StringtoHex(byte value)
to Hex
int d1 = (value >> 4) & 0xF;
int d2 = value & 0xF;
return Character.forDigit(d1, 16) + "" + Character.forDigit(d2, 16);
StringtoHex(byte value)
Returns a hexadecimal representation of the byte value.
StringBuilder result;
result = new StringBuilder();
result.append(HEX_DIGIT[(value >> 4) & 0x0f]);
result.append(HEX_DIGIT[(value) & 0x0f]);
return result.toString();
StringtoHex(byte... bs)
Return hex encoded string from bytes
StringBuilder result = new StringBuilder(bs.length * 2);
for (byte b : bs) {
    result.append(HEXDIGITS[(b >> 4) & 0xF]);
    result.append(HEXDIGITS[(b & 0xF)]);
return result.toString();
StringtoHex(byte... bytes)
to Hex
String returnString = "";
for (byte b : bytes) {
    returnString = returnString + String.format("%02x", b) + " ";
return returnString;