Java Utililty Methods Hex Print

List of utility methods to do Hex Print

Description

The list of methods to do Hex Print are organized into topic(s).

Method

voidprintHex(byte b)
print Hex
int i = b & 0xff;
int hi = i / 16;
int lo = i % 16;
if (hi < 10) {
    System.out.print((char) ('0' + hi));
} else {
    System.out.print((char) ('a' + hi - 10));
if (lo < 10) {
    System.out.print((char) ('0' + lo));
} else {
    System.out.print((char) ('a' + lo - 10));
StringprintHex(byte[] array)
print Hex
return printHex(array, 0, array.length);
StringprintHex(byte[] array, int offset, int len)
Get a hexadecimal representation of a byte array starting at offset index for len bytes, with each octet separated by a space.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
    byte b = array[offset + i];
    if (sb.length() > 0)
        sb.append(' ');
    sb.append(digits[b >> 4 & 0x0F]);
    sb.append(digits[b & 0x0F]);
return sb.toString();
StringprintHex(byte[] b)
print Hex
StringBuffer res = new StringBuffer();
StringBuffer t, t1;
for (int i = 0; i < b.length; i++) {
    t = new StringBuffer(Integer.toHexString(b[i]));
    if (t.length() > 2) {
        t1 = new StringBuffer();
        t1.append(t.charAt(t.length() - 2));
        t1.append(t.charAt(t.length() - 1));
...
voidprintHex(byte[] bytes)
Print bytes in Hex format.
if (bytes == null)
    return;
int lines = bytes.length / 16;
if (bytes.length % 16 > 0) {
    lines++;
String readable = new String(bytes);
int maxlen = readable.length();
...
voidprintHex(byte[] bytes)
Print out a byte array in hexadecimal
for (byte b : bytes)
    System.out.print(byteToHexString(b));
voidprintHex(byte[] data)
print Hex
for (byte b : data)
    System.out.printf("0x%x ", b);
System.out.println();
StringprintHex(byte[] field, int start, int len)
print Hex
StringBuffer sb = new StringBuffer((field.length * 3) - 1);
int stop = field.length < len ? field.length : (start + len);
for (int i = start; i < stop; i++) {
    int b = (field[i] >> 4) & 0x0000000F;
    if (b < 10) {
        sb.append(b);
    } else {
        sb.append((char) ('A' + b - 10));
...
char[]printHexa(final byte b)
print Hexa
final char[] result = new char[2];
result[0] = HEXA_CHARS_UPPER[(b >> 4) & 0xF];
result[1] = HEXA_CHARS_UPPER[b & 0xF];
return result;
StringprintHexBytes(byte[] _theBytes)
print Hex Bytes
String _sRet = "";
for (int i = 0; i < _theBytes.length; i++) {
    if (i != 0 && i % 16 == 0)
        _sRet = _sRet + " \n";
    try {
        _sRet = _sRet + String.format(" %02X", (_theBytes[i] & 0xff));
    } catch (IllegalFormatException e) {
        e.printStackTrace();
...