9 examples of 'python int to str' in Python

Every line of 'python int to str' 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
this disclaimer
16def int_to_str(i):
17 s = hex(i)[2:]
18 res = ""
19 for i in range(0, len(s), 2):
20 res += chr(int(s[i] + s[i+1], 16))
21 return res
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

35def int_to_hex(i):
36 return format(i, 'x')
58def to_int(input):
59 try:
60 return int(input)
61 except ValueError:
62 raise Exception ('Input is not an integer')
75def to_int(value):
76 return int(value)
170def int_binstr(n):
171 '''
172 '''
173 #
174 bStr = ''
175 #
176 if n < 0: raise ValueError, "must be a positive integer"
177 if n == 0: return '000000000000'
178
179 i = 0
180 while i < 12:
181 if n > 0:
182 bStr = str(n % 2) + bStr
183 n = n >> 1
184 else:
185 bStr = '0' + bStr
186 i += 1
187
188 return bStr
23def int2bytes(x):
24 output = ""
25 while x != 0:
26 output += chr(x%0x100)
27 x >>= 8
28 return output
81def integer_from_Intel2(int_string):
82 # return first integer decoded from 2-byte-intel-format string
83 # jjk 04/25/96
84 return integer_from_Intel(int_string[:2])
171def decodeint(s):
172 return int(binascii.hexlify(s[:32][::-1]), 16)
102def int2dotted_hex(p_int, p_size):
103 """
104 @param p_int: is the integer to convert to a dotted hex string such as 'A1.B2' or 'C4.D3.E2'
105 @param p_size: is the number of bytes to convert - either 2 or 3
106 """
107 l_ix = _get_factor(p_size)
108
109 l_hex = []
110 l_int = int(p_int)
111 try:
112 while l_ix > 0:
113 l_byte, l_int = divmod(l_int, l_ix)
114 l_hex.append("{:02X}".format(l_byte))
115 l_ix = int(l_ix / 256)
116 return str('.'.join(l_hex))
117 except (TypeError, ValueError) as e_err:
118 print('ERROR in converting int to dotted Hex {} {} - Type:{} - {}'.format(p_int, l_ix, type(p_int), e_err))

Related snippets