public static function decodeHex($hex)
{
if (!is_string($hex) || !ctype_xdigit($hex) && '0x' != substr($hex, 0, 2)) {
throw new \Exception('Argument must be a string of hex digits.');
}
$hex = strtolower($hex);
// if it has a prefix of 0x this needs to be trimed
if (substr($hex, 0, 2) == '0x') {
$hex = substr($hex, 2);
}
$hexLen = strlen($hex);
for ($dec = '0', $i = 0; $i < $hexLen; $i++) {
$current = strpos(self::HEX_CHARS, $hex[$i]);
$dec = Math::add(Math::mul($dec, 16), $current);
}
return $dec;
}