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)
377
378 self.assertEqual(exp, res)
379
380 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: int
8 :rtype: str
9 """
10 if not num:
11 return "0"
12
13 result = []
14 while num and len(result) != 8:
15 h = num & 15
16 if h < 10:
17 result.append(str(chr(ord('0') + h)))
18 else:
19 result.append(str(chr(ord('a') + h-10)))
20 num >>= 4
21 result.reverse()
22
23 return "".join(result)
30def hex2dec(hex):
31 """ Convert and hex value in a decimal number
32 """
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 = None
52 return h
284def test_convert_base_decimal():
285 base_10 = list(map(str, range(10)))
286 # Test that decimal values agree with python conversion
287 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]

Related snippets