# 9 examples of 'convert hex to decimal python' in Python

Every line of 'convert hex to decimal python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``372def test__DECIMAL_to_python(self):373    """Convert a MySQL DECIMAL to a Python decimal.Decimal type"""374    data = b'3.14'375    exp = Decimal('3.14')376    res = self.cnv._DECIMAL_to_python(data)377378    self.assertEqual(exp, res)379380    self.assertEqual(self.cnv._DECIMAL_to_python,381                     self.cnv._NEWDECIMAL_to_python)``
``33def test_dec_to_hex(self):34    self.assertEqual(conversion.decimal_to_hex(30), '1E')``
``5def toHex(self, num):6    """7    :type num: int8    :rtype: str9    """10    if not num:11        return "0"1213    result = []14    while num and len(result) != 8:15        h = num &amp; 1516        if h &lt; 10:17            result.append(str(chr(ord('0') + h)))18        else:19            result.append(str(chr(ord('a') + h-10)))20        num &gt;&gt;= 421    result.reverse()2223    return "".join(result)``
``30def hex2dec(hex):31    """ Convert and hex value in a decimal number32    """33    return int(hex, 16)``
``96def dec_to_hex(dec):97    return str(format(dec, "x"))``
``26def _hex2dec(s):27	return str(int(s,16))``
``45def to_hex(number):46    if number is not None:47        h = hex(number)48        if h.endswith('L'):49            h = h[:-1]50    else:51        h = None52    return h``
``284def test_convert_base_decimal():285    base_10 = list(map(str, range(10)))286    # Test that decimal values agree with python conversion287    for i in it.chain(range(-10, 10), range(-1000, 1000, 7)):288        text_16 = hex(i).replace('0x', '')289        text_10 = _convert_hexstr_base(text_16, base_10)290        assert int(text_16, 16) == int(text_10, 10)``
``22def _double_to_hex(val):23	return struct.unpack('Q', struct.pack('d', val))[0]``