<jupyter_start><jupyter_text>**Hexadecimal output:** Exercise 2.4Hexadecimal numbers are fairly common in the world of computers. Actually, that’s not entirely true: some programmers use them all of the time. Other programmers, typically using high-level languages and doing things such as Web development, barely ever remember how to use them.Now, the fact is that I barely use hexadecimal numbers in my day-to-day work. And even if I were to need them, I could use Python’s built-in hex function and 0x prefix. The former takes an integer and returns a hex string; the latter allows me to enter a number using hexadecimal notation, which can be more convenient. Thus, 0x50 is 80, and hex(80) will return the string 0x50.For this exercise, you need to write a program that takes a hex number and returns the decimal equivalent. That is, if the user enters 50, then we will assume that it is a hex number (equal to 0x50), and will print the value 80 on the screen.<jupyter_code>conversion_table = {
        'A': 10,
        'B': 11,
        'C': 12,
        'D': 13,
        'E': 14,
        'F': 15
    }

def conver_hex_char_to_dec_num(hex_char):
    
    _hex_char = hex_char.upper()
    
    if '0' <= _hex_char <= '9':
        dec = int(_hex_char)
    elif 'A' <= _hex_char <= 'F':
        dec = conversion_table[_hex_char]
    else:
        raise ValueError("invalid hex char {0}".format(hex_char))
        
    return dec
    
    
def hex_to_dec(hex_str):
    
    result = None
    
    for hex_char in hex_str:
        dec_num = conver_hex_char_to_dec_num(hex_char)
        
        if result is None:
            result = dec_num
        else:
            result = result * 16 + dec_num
        
    return result

print hex_to_dec('ff')
[ord(_) for _ in '0123456789ABCDEFabcdef']
5 in range(4,10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07780195865070728, 'fraction_numerical': 0.027747551686615888, 'mean_word_length': 2.8553459119496853, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '232176', 'license': 'Unlicense', 'n_tokens_mistral': 600, 'n_tokens_neox': 557, 'n_words': 229, 'path': 'numeric-types/ex 2.4 hexadecimal output.ipynb', 'repo_name': 'python-practice/practice-makes-python-solutions', 'size': '1838'}