10 examples of 'python hex to string' in Python

Every line of 'python hex to string' 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
292def hexToString(hexString):
293 '''
294 Simple method to convert an hexadecimal string to ascii string
295
296 @param hexString: A string in hexadecimal format
297 @return: A tuple (status,statusContent), where statusContent is an ascii string in case status = 0 or an error in case status = -1
298 '''
299 string = ''
300 if len(hexString) % 2 != 0:
301 hexString = '0'+hexString
302 try:
303 for i in range(0,len(hexString),2):
304 string += chr(int(hexString[i]+hexString[i+1],16))
305 except:
306 return (-1,'Error in hexadecimal conversion')
307 return (0,string)
81def to_hex(self):
82 # Convert to hexadecimal string representation
83 alpha = '' if self._alpha >= 1.0 else '{:02X}'.format(int(self._alpha*255))
84 return '#{:02X}{:02X}{:02X}{a}'.format(*(int(c*255) for c in self._rgba[:3]), a=alpha)
25def hex2bin(hexstr):
26 """Convert a hexdecimal string to binary string, with zero fillings. """
27 num_of_bits = len(hexstr) * 4
28 binstr = bin(int(hexstr, 16))[2:].zfill(int(num_of_bits))
29 return binstr
24def to_hexstr(data):
25 return ' '.join('%02x' % b for b in data)
35def int_to_hex(i):
36 return format(i, 'x')
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
18def hex_to_binary(hex_string):
19 return ''.join([b.decode('hex') for b in hex_string.split(" ")])
11def to_hex(data):
12 try:
13 data = memoryview(data)
14 except TypeError:
15 data = memoryview(bytes(data))
16 if dump_hex.limit is None or len(data) < dump_hex.limit:
17 return data.hex()
18 else:
19 return "{}... ({} bytes total)".format(
20 data[:dump_hex.limit].hex(), len(data))
51def get_hex_string(value):
52 v = '0x'
53 for c in value:
54 new_hex = hex(ord(c))[2:].upper()
55 if len(new_hex) < 2:
56 new_hex = '0' + new_hex
57 v += new_hex
58 return v
13def hex_to_bin(s):
14 return binascii.unhexlify(s.replace(' ', ''))

Related snippets