h is set to a string with allowed hex digits.
The string is converted to upper case and illegal characters are filtered out.
The leftmost character is converted to a number between 0 and 16.
The length of the whole string - 1 is calculated to determine the significance of the first digit - and whether other characters may follow.

Finally the decimal value of the leftmost digit is calculated and if there are digits left over, the Custom Function calls itself with the remaining digits which are then added to the result.