Every line of 'python ascii to hex' 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.
25 def 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
13 def bin2hex(s): 14 return '%0*X' % ((len(s) + 3) // 4, int(s, 2))
11 def 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))
113 def b2a_hex(s): 114 return _b2a_hex(s).decode('us-ascii')
13 def hex_to_bin(s): 14 return binascii.unhexlify(s.replace(' ', ''))
24 def to_hexstr(data): 25 return ' '.join('%02x' % b for b in data)
28 def _hex_to_bin_byte(hex_byte): 29 #TODO2: Absolutely sure there is a library function for this 30 hex_down = '0123456789abcdef' 31 hex_up = '0123456789ABDCEF' 32 value = 0 33 for i in xrange(2): 34 value *= 16 35 try: 36 value += hex_down.index(hex_byte[i]) 37 except ValueError: 38 try: 39 value += hex_up.index(hex_byte[i]) 40 except ValueError: 41 raise IdError 42 return chr(value)
45 def 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
18 def hex_to_binary(hex_string): 19 return ''.join([b.decode('hex') for b in hex_string.split(" ")])
35 def int_to_hex(i): 36 return format(i, 'x')