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

chartoHexChar(int nibble)
Convert a nibble to a hex character
return hexDigit[(nibble & 0xF)];
chartoHexChar(int paramInt)
to Hex Char
return (char) (paramInt + (paramInt < 10 ? 48 : 55));
chartoHexChar(int value)
Convert the given value, which must be between 0 and 15, into its equivalent hex character between 0 and F.
switch (value) {
case 0:
    return '0';
case 1:
    return '1';
case 2:
    return '2';
case 3:
...
char[]toHexCharArray(byte[] input)
to Hex Char Array
int m = input.length;
int n = 2 * m;
int l = 0;
char[] output = new char[n];
for (int k = 0; k < m; k++) {
    byte v = input[k];
    int i = (v >> 4) & 0xf;
    output[l++] = (char) (i >= 10 ? ('a' + i - 10) : ('0' + i));
...
chartoHexCharFromBin(final String bin)
to Hex Char From Bin
String bits = stripBinaryPrefix(bin);
while (bits.length() < BITS_PER_HEX_DIGIT) {
    bits = "0" + bits;
if (bits.length() > BITS_PER_HEX_DIGIT) {
    throw new IllegalArgumentException(
            "Input bit string \"" + bin + "\" is too long to be a hexadecimal character.");
int value = Integer.parseInt(bits, BINARY_RADIX);
return (hexSymbols[value].charAt(0));
char[]toHexChars(byte[] bs)
to Hex Chars
char[] cbuf = new char[bs.length * 2];
toHexChars(bs, cbuf);
return cbuf;
char[]toHexChars(byte[] bytes)
Converts the given byte array to a hex character array.
char[] hex = new char[bytes.length * 2];
for (int i = 0, j = 0; i < bytes.length; i++) {
    hex[j++] = HEX[(bytes[i] >> 4) & 0xF];
    hex[j++] = HEX[bytes[i] & 0xF];
return hex;
char[]toHexChars(final int b)
to Hex Chars
final char left = HEX_DIGITS[(b >>> 4) & 0x0F];
final char right = HEX_DIGITS[b & 0x0F];
return new char[] { left, right };
StringtoHexDec(byte[] bytes)
Format first 200 bytes into hex, followed by decimal presentation.
final StringBuffer buf = new StringBuffer();
final int max = Math.min(200, bytes.length);
for (int i = 0; i < max; ++i) {
    final String hex = Integer.toHexString(bytes[i] & 0xff);
    if (hex.length() == 1)
        buf.append("0");
    buf.append(hex);
    buf.append(" ");
...
inttoHexDigit(char ch)
to Hex Digit
if ((ch <= '9') && (ch >= '0')) {
    return (ch - '0');
if ((ch >= 'a') && (ch <= 'f')) {
    return ((ch - 'a') + 10);
if ((ch < 'A') || (ch > 'F')) {
    throw new IllegalArgumentException("Illegal hexadecimal charcter + " + ch);
...