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[] bytes)
Creates a String from a byte array with each byte in a "Big Endian" hexidecimal format.
if (bytes == null) {
    return "";
return toHexString(bytes, 0, bytes.length);
StringtoHexString(byte[] bytes)
Converts a byte array to a hex String by HNF order.
return toHexString(bytes, true);
StringtoHexString(byte[] bytes)
to Hex String
int length = bytes.length;
StringBuffer sb = new StringBuffer(length * 2);
int x = 0;
int n1 = 0, n2 = 0;
for (int i = 0; i < length; i++) {
    if (bytes[i] >= 0)
        x = bytes[i];
    else
...
StringtoHexString(byte[] bytes)
Creates a hexadecimal representation of the specified bytes.
if (bytes == null) {
    return null;
StringBuilder buffer = new StringBuilder(bytes.length * 2);
for (byte aByte : bytes) {
    int b = aByte & 0xFF;
    if (b < 0x10) {
        buffer.append('0');
...
StringtoHexString(byte[] bytes)
to Hex String
char[] values = new char[bytes.length * 2];
int i = 0;
for (byte b : bytes) {
    values[i++] = LETTERS[((b & 0xF0) >>> 4)];
    values[i++] = LETTERS[b & 0xF];
return String.valueOf(values);
StringtoHexString(byte[] bytes)
Convert bytes into hexidecimal string
StringBuffer buf = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    short b = byteToShort(bytes[i]);
    String hex = Integer.toString(b, 0x10);
    if (b < 0x10) 
        buf.append('0');
    buf.append(hex);
    if (i < bytes.length - 1)
...
StringtoHexString(byte[] bytes)
Convert a byte array into a hexadecimal String representation.
final StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    sb.append(digits[(bytes[i] >> 4) & 0x0f]);
    sb.append(digits[bytes[i] & 0x0f]);
return sb.toString();
StringtoHexString(byte[] bytes)
Converts bytes to HEX String.
char[] hexArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
char[] hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++) {
    v = bytes[j] & 0xFF;
    hexChars[j * 2] = hexArray[v / 16];
    hexChars[j * 2 + 1] = hexArray[v % 16];
return new String(hexChars);
StringtoHexString(byte[] bytes)
to Hex String
StringBuffer sb = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    if (i > 0 && i % 16 == 0) {
        sb.append("\n");
    } else if (i > 0 && i % 8 == 0) {
        sb.append(" ");
    String val = Integer.toHexString(bytes[i] & 0xFF);
...
StringtoHexString(byte[] bytes, boolean addPrefix)
Convert a byte array to a hex string
int base;
char[] chars;
if (addPrefix) {
    chars = new char[bytes.length * 2 + 2];
    chars[0] = '0';
    chars[1] = 'x';
    base = 2;
} else {
...