is there a pythonic and synthetic way (maybe some standard module) to
pack an integer (maybe a *VERY* big one) into a string? like this:
number = 252509952
hex(number)
'0xf0cff00'
so i would like a string like '\xf0\xcf\xf0\x00'
i wrote some code to do it, so ugly i am ashamed to post
On Jul 24, 7:16 pm, superpollo u...@example.net wrote:
thanks a lot, but [struct] does not work for large integers:
Since the struct module is designed specifically for C-style structs,
it's definitely not going to handle arbitrary-length integers on its
own. You could chop up your Python
On Jul 24, 3:28 pm, superpollo u...@example.net wrote:
is there a pythonic and synthetic way (maybe some standard module) to
pack an integer (maybe a *VERY* big one) into a string? like this:
number = 252509952
hex(number)
'0xf0cff00'
so i would like a string like
superpollo u...@example.net writes:
number = 252509952
hex(number)
'0xf0cff00'
so i would like a string like '\xf0\xcf\xf0\x00'
def encode(number):
h = '%x' % number
if len(h) % 2 == 1:
h = '0' + h
return h.decode('hex')
--