7 examples of 'python hexadecimal to decimal' in Python

Every line of 'python hexadecimal to decimal' 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
26def _hex2dec(s):
27 return str(int(s,16))
30def hex2dec(hex):
31 """ Convert and hex value in a decimal number
32 """
33 return int(hex, 16)
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)
33def test_dec_to_hex(self):
34 self.assertEqual(conversion.decimal_to_hex(30), '1E')
182def decodeaDecimal(bv, validate=False):
183 return Decimal(binary.signedIntFromBV(bv[78:94]))/Decimal('10')
96def dec_to_hex(dec):
97 return str(format(dec, "x"))
894def hex2char(hexadec):
895 """Answers the unicode char that matcher the hex value. Answer None if
896 conversion fails.
897
898 >>> hex(ord('A'))
899 '0x41'
900 >>> hex2dec('41')
901 65
902 >>> hex2char('41')
903 'A'
904 >>> hex2char('FFZ') is None
905 True
906 """
907 v = hex2dec(hexadec)
908 if v is not None:
909 return chr(v)
910 return None

Related snippets