@Throws(HexFormatException::class) fun hexToDecimal(hex: String): Int { var decimalValue = 0 for (i in 0 until hex.length) { if (!(hex[i] >= '0' && hex[i] <= '9' || hex[i] >= 'A' && hex[i] <= 'F')) throw HexFormatException( hex ) val hexChar = hex[i] decimalValue = decimalValue * 16 + hexCharToDecimal(hexChar) } return decimalValue }
Converts a hex string into a decimal number and throws a HexFormatException if the string is not a hex string