public static int hexToInt(String value) throws NumberFormatException {
        int result = 0;
        int multiplier = 1;

        for (int i = value.length() - 1; i >= 0; i--, multiplier *= 16) {
            char digit = value.charAt(i);
            if (digit >= '0' && digit <= '9')
                result += (digit - '0') * multiplier;
            else if (digit >= 'a' && digit <= 'f')
                result += (digit - 'a' + 10) * multiplier;
            else if (digit >= 'A' && digit <= 'F')
                result += (digit - 'A' + 10) * multiplier;
            else
                throw new NumberFormatException();
        }

        return result;
    }