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

inttoHexDigit(char ch, int index)
to Hex Digit
int digit = Character.digit(ch, 16);
if (digit == -1) {
    throw new RuntimeException("Illegal hexadecimal charcter " + ch + " at index " + index);
return digit;
chartoHexDigit(int d)
to Hex Digit
return (char) (d < 0xA ? d + '0' : d - 0xA + 'A');
chartoHexDigit(int d)
to Hex Digit
switch (d) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
...
chartoHexDigit(int h)
to Hex Digit
char out;
if (h <= 9)
    out = (char) (h + 0x30);
else
    out = (char) (h + 0x37);
return out;
chartoHexDigit(int i)
Return the correct hex character for this integer value.
return "0123456789abcdef".charAt(i);
chartoHexDigit(int number)

Return the single digit character representing the HEX encoding of the lower four bits of a given integer.

switch (number & 0x0F) {
case 0x00:
    return '0';
case 0x01:
    return '1';
case 0x02:
    return '2';
case 0x03:
...
StringtoHexDigit(int value, int digitPosition)
Converts a base-ten integer to a hexadecimal value at a particular digit.
int digitValue = (value >>> (digitPosition * 4)) & 0xf;
return Integer.toHexString(digitValue);
StringtoHexDigits(byte[] bytes)
to Hex Digits
StringBuffer encoded = new StringBuffer(bytes.length * 2);
for (int eachByte = 0; eachByte < bytes.length; eachByte++) {
    encoded.append(toHexDigits(bytes[eachByte]).toUpperCase());
return encoded.toString();
StringtoHexDigits(int value)
to Hex Digits
return String.format("%02x", value);
StringtoHexDump(byte[] ab, int cBytesPerLine)
Convert a byte array to a hex dump.
int cb = ab.length;
if (cb == 0) {
    return "";
int cDigits = 0;
int cbTemp = cb - 1;
do {
    cDigits += 2;
...