Java Utililty Methods Hex to Int

List of utility methods to do Hex to Int

Description

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

Method

intconvertHexBytesToInt(byte[] hex)
convert Hex Bytes To Int
String hexString = stringify_nospaces(hex);
String asciiString = convertHexToString(hexString);
return convertHexStringToInt(asciiString);
intconvertHexDigitAsInt(char c)
convert Hex Digit As Int
if (c >= '0' && c <= '9')
    return c - '0';
if (c >= 'A' && c <= 'F')
    return c - 'A' + 10;
if (c >= 'a' && c <= 'f')
    return c - 'a' + 10;
return 0;
intconvertHexStringToInt(String hex)
convert Hex String To Int
return Integer.valueOf(hex, 16);
intconvertHexStringToInt(String hexString)
convert Hex String To Int
int val = 0;
if ((hexString != null) && (hexString.length() > 0)) {
    String hexVal = hexString.trim();
    int ndex = 0;
    if (hexVal.startsWith("0x"))
        ndex = 2;
    hexVal = hexVal.substring(ndex);
    val = Integer.parseInt(hexVal, 16);
...
StringconvertHexToDec(String in)
convert Hex To Dec
if (in == null) {
    return null;
} else {
    if (in.equals("**"))
        return "*";
    int hex = Integer.parseInt(in, 16);
    return String.valueOf(Integer.toString(hex));
intconvertHexToInt(String hex)
Wandle 4-stellige Hexadezimalkodierung in Nummer um (z.B.
hex = hex.toLowerCase();
char[] chex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
int[] c = { 0, 0, 0, 0 };
for (int j = 0; j < 4; j++) {
    for (int i = 0; i < 16; i++) {
        if (hex.charAt(j) == chex[i]) {
            c[j] = i;
int no = (c[3] + (16 * c[2]) + (16 * 16 * c[1]) + (16 * 16 * 16 * c[0]));
return no;
inthexChar2dec(char hex)
hex Chardec
if (hex > 47 && hex < 58) {
    hex -= 48;
} else if (hex > 64 && hex < 71) {
    hex -= 55;
} else if (hex > 96 && hex < 103) {
    hex -= 87;
} else {
    throw new RuntimeException(hex + "is not a valid hex char.");
...
bytehexChar2Int(char ch)
hex Char Int
boolean f1 = ch >= '0' && ch <= '9';
boolean f2 = ch >= 'A' && ch <= 'F';
boolean f3 = ch >= 'a' && ch <= 'f';
if (!(f1 || f2 || f3)) {
    return -1;
if (f1) {
    return (byte) (ch - '0');
...