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

byte[]toHexBytes(byte[] toBeConverted)
to Hex Bytes
if (toBeConverted == null) {
    throw new NullPointerException("Parameter to be converted can not be null");
byte[] converted = new byte[toBeConverted.length * 2];
for (int i = 0; i < toBeConverted.length; i++) {
    byte b = toBeConverted[i];
    converted[i * 2] = HEX_BYTES[b >> 4 & 0x0F];
    converted[i * 2 + 1] = HEX_BYTES[b & 0x0F];
...
char[]toHexChar(byte[] bArray)
to Hex Char
char[] digitChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
char[] charDigest = new char[bArray.length * 2];
for (int i = 0; i < bArray.length; i++) {
    charDigest[i * 2] = digitChars[(bArray[i] >>> 4) & 0X0F];
    charDigest[i * 2 + 1] = digitChars[bArray[i] & 0X0F];
return charDigest;
voidtoHexChar(char ch, StringBuffer sb)
to Hex Char
if ((ch & 0xFF00) != 0)
    toHexByte((byte) ((ch >> 8) & 0xFF), sb);
toHexByte((byte) (ch & 0xFF), sb);
chartoHexChar(int b)
to Hex Char
return (char) (b < 10 ? ('0' + b) : ('A' + b - 10));
chartoHexChar(int digit)
'0' - '9', 'A', 'B', 'C', 'D', 'E', 'F'
digit &= 0x0F; 
if (digit < 10) {
    return (char) ('0' + digit);
return (char) (('A' - 10) + digit);
chartoHexChar(int digitValue)
Convert a digital value to hex
if (digitValue < 10) {
    return (char) ('0' + digitValue);
} else {
    return (char) ('A' + (digitValue - 10));
chartoHexChar(int digitValue)
to Hex Char
if (digitValue < 10)
    return (char) ('0' + digitValue);
else
    return (char) ('A' + (digitValue - 10));
chartoHexChar(int i)
convert a integer into a hexadecimal character
if ((0 <= i) && (i <= 9)) {
    return (char) ('0' + i);
} else {
    return (char) ('a' + (i - 10));
chartoHexChar(int i)
to Hex Char
if (i >> 4 != 0)
    throw new RuntimeException();
return (char) ((i < 10) ? i + '0' : i - 10 + 'a');
chartoHexChar(int i)
Standard algorithm to convert an int into a hex char.
if (0 <= i && i <= 9) {
    return (char) ('0' + i);
} else {
    return (char) ('a' + i - 10);